package hotel.switchs.oversea.online.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import hotel.base.oversea.constant.*;
import hotel.base.oversea.constant.enums.*;
import hotel.base.oversea.dto.meituan.MtHotelGoodsBookRuleDto;
import hotel.base.oversea.dto.meituan.MtHotelGoodsDto;
import hotel.base.oversea.dto.meituan.MtHotelGoodsInvoiceDto;
import hotel.base.oversea.dto.switchs.SwitchCreateRoomDto;
import hotel.base.oversea.entity.SwitchHotelActiveTagEntity;
import hotel.base.oversea.entity.SwitchPriceBaseSetEntity;
import hotel.base.oversea.entity.master.CompareHotelBasicRoom;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.vo.MtOrderCheckVo;
import hotel.base.oversea.vo.PirceModelVo;
import hotel.base.oversea.vo.meituan.MtHotelDownVo;
import hotel.base.oversea.vo.meituan.request.goods.*;
import hotel.base.oversea.vo.meituan.request.room.CompareRoomForFpVO;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsPriceBaseDetailVo;
import hotel.switchs.oversea.api.VO.*;
import hotel.switchs.oversea.api.VO.CtripSellRuleVo;
import hotel.switchs.oversea.api.VO.request.*;
import hotel.switchs.oversea.api.entity.*;
import hotel.switchs.oversea.online.config.service.RedisService;
import hotel.switchs.oversea.online.mapper.*;
import hotel.switchs.oversea.online.service.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;

/**
 * @Auther: lmf
 * @Date: 2020/09/23/14:23
 * @Description:
 */
@Service
@Slf4j
public class SwitchHotelUpServiceImpl extends BaseServiceImpl<SwitchHotelUpEntity> implements SwitchHotelUpService {
    @Autowired
    SwitchHotelUpMapper switchHotelUpMapper;
    @Autowired
    SwitchSubHotelInfoService switchSubHotelInfoService;
    @Autowired
    SwitchHotelUpLogMapper switchHotelUpLogMapper;
    @Autowired
    SwitchCreateRoomMapper switchCreateRoomMapper;
    @Autowired
    SwitchRestTempaleUtilsService switchRestTempaleUtilsService;
    @Autowired
    SwitchPushRoomService switchPushRoomService;
    @Autowired
    RedisService redisService;
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    SwitchHotelActiveTagMapper switchHotelActiveTagMapper;

    @Autowired
    SwitchCreateRoomFailureMapper switchCreateRoomFailureMapper;

    @Autowired
    SwitchBasicRoomTypeService switchBasicRoomTypeService;

    @Autowired
    SwitchCreateSubHotelMapper switchCreateSubHotelMapper;

    @Autowired
    SwitchRoomPriceService switchRoomPriceService;
    @Autowired
    SwitchPushRoomLogMapper switchPushRoomLogMapper;

    @Autowired
    SwitchCreateBasicRoomMapper switchCreateBasicRoomMapper;

    @Autowired
    SwitchHotelRoomPriceAndStatusLogMapper switchHotelRoomPriceAndStatusLogMapper;

    @Autowired
    SwitchFixPointSetMapper switchFixPointSetMapper;

    @Autowired
    SwitchPriceBaseSetMapper switchPriceBaseSetMapper;

    @Autowired
    SwitchHotelPriceSetRelationMapper switchHotelPriceSetRelationMapper;

    @Autowired
    SwitchHotelPriceSetRelationLogMapper switchHotelPriceSetRelationLogMapper;

    private static final String SWITCH_HOTEL_ROOM_PRICE_AND_STATUS_LOG_TABLE="switch_hotel_room_price_and_status_log_";

    /**
     * 美团的地址
     */
    private static final String MEI_TUAN_URL = CommonUrlConstants.MEITUAN_HOST + "/";
    /**
     * 标记是否上架
     */
    private final static String SWITCH_HOTEL_UP_TIME = "switch_hotel_up_time";

    @Autowired
    SwitchRoomStatusLogMapper switchRoomStatusLogMapper;

    @Autowired
    private SwitchCreateBasicRoomService switchCreateBasicRoomService;

    @Autowired
    private SwitchHotelOutPutMapper switchHotelOutPutMapper;


    @Autowired
    private SwitchHotelActiveGenreMapper switchHotelActiveGenreMapper;

    @Autowired
    private SwitchHotelActiveListMapper switchHotelActiveListMapper;
    @Autowired
    SwitchHotelLevelMapper switchHotelLevelMapper;
    @Autowired
    SwitchHotelLevelLogMapper switchHotelLevelLogMapper;
    @Autowired
    SwitchOrderInfoMapper switchOrderInfoMapper;
    @Autowired
    SwitchHotelRoomSaleMapper switchHotelRoomSaleMapper;

    @Autowired
    SwitchJoinActiveHotelMapper  switchJoinActiveHotelMapper;



    /**
     * 1. 线程池显示的调用了shutdown()之后，再向线程池提交任务的时候，如果你配置的拒绝策略是ThreadPoolExecutor.AbortPolicy的话，这个异常就被会抛出来。
     * 2. 当你的排队策略为有界队列，并且配置的拒绝策略是ThreadPoolExecutor.AbortPolicy，当线程池的线程数量已经达到了maximumPoolSize的时候，你再向它提交任务，就会抛出ThreadPoolExecutor.AbortPolicy异常。
     * Executors.newFixedThreadPool(20)
     */
    //private ExecutorService executorService = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    //private ExecutorService executorServiceByHotel = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    /***
     * @Author: lmf
     * @Date: 2020/12/7
     * 下架全部酒店，保持在售状态
     */
    public Result<Object> downHotelAll(SetHotelUpVo setHotelUpVo) {
        new DownHotelThread(setHotelUpVo).run();
        return new Result<>(CommonConstants.SUCCESS, "下架中.......");
    }

    @Override
    public Result<Object> getUpHotelDesc() {
        List<Integer> list = switchHotelUpMapper.getUpHotelDesc();
        return new Result<>(GsonUtils.GsonString(list), "success");
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/7
     * 下架全部酒店
     */
    class DownHotelThread implements Runnable {
        private SetHotelUpVo setHotelUpVo;

        public DownHotelThread(SetHotelUpVo setHotelUpVo) {
            this.setHotelUpVo = setHotelUpVo;
        }

        @Override
        public void run() {
            long startTime = System.currentTimeMillis();
            //1.获取所有可以上架的酒店id
            List<Integer> ids = switchHotelUpMapper.selectSaleHotelList();
            List<List<Integer>> hotelIds = ListUtils.parititon(ids, 50);
            String idAll = "";
            int size = 0;
            log.info("=============当前的上架酒店长度为{}", hotelIds.size());
            int times = 0;
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities = new ArrayList<>();
            SwitchHotelUpLogEntity switchHotelUpLogEntity;
            for (List<Integer> h : hotelIds) {
                //crtip 关闭,其余渠道正常开售
                Map<String, Object> updateChannelVoMap = new HashMap<>();
                updateChannelVoMap.put("hotelIDs", hotelIds);
                updateChannelVoMap.put("cBookable", 0);
                updateChannelVoMap.put("qBookable", 1);
                updateChannelVoMap.put("channelABookable", 1);
                updateChannelVoMap.put("b2bBookable", 1);
                Result<Object> result= switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                if (result.getCode() == CommonConstants.SUCCESS) {
                    log.info("=========下架成功,这是第几次调用为{}===========", times++);
                    idAll += StringUtils.join(h, ",");
                    for (Integer hotelId : h) {
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(0);
                        switchHotelUpLogEntity.setUsername("system");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(h, ","),0);
                }else if(result.getMsg().toString().contains("MIPHotel")){
                    log.info("=========下架成功,这是第几次调用为{}===========", times++);
                    idAll += StringUtils.join(h, ",");
                    for (Integer hotelId : h) {
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(0);
                        switchHotelUpLogEntity.setUsername("system");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(h, ","),0);
                }
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
            long endTime = System.currentTimeMillis();
            log.info("==============下架发费的时间为{}", (endTime - startTime));
        }
    }


    /***
     * @Author: lmf
     * @Date: 2020/10/6
     * 全部售卖按钮
     */
    @SneakyThrows
    @Override
    public Result<Object> upHotelAllNew(SetHotelUpVo setHotelUpVo) {
        new UpHotelThread(setHotelUpVo).run();
        return new Result<>(CommonConstants.SUCCESS, "上架中.....");
    }

    class UpHotelThread implements Runnable {
        private SetHotelUpVo setHotelUpVo;

        public UpHotelThread(SetHotelUpVo setHotelUpVo) {
            this.setHotelUpVo = setHotelUpVo;
        }

        @Override
        public void run() {
            long startTime = System.currentTimeMillis();
            //1.获取所有可以上架的酒店id
            List<SwitchHotelUpVo> switchHotelUpVos = switchHotelUpMapper.selectHotelStatus(3);
            log.info("========上架前可循环一次所有上架酒店,目前有{}个酒店====", switchHotelUpVos.size());
            List<Integer> can = new ArrayList<>();
            for (SwitchHotelUpVo switchHotelUpVo : switchHotelUpVos) {
                Integer[] hotelId = new Integer[2];
                hotelId[0] = switchHotelUpVo.getMtHotelId();
                //调用美团接口检查是否有被拉入黑名单的酒店
                String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_HOTEL_FAILURE.getUrl();
                Map<String, Object> params = new HashMap<>();
                params.put("hotelIds", hotelId);
                Result<List<MtHotelDownVo>> result = switchRestTempaleUtilsService.sendReuestToMtCheckHotelFailure(url, params);
                List<MtHotelDownVo> mtHotelDownVos = result.getData();
                if (mtHotelDownVos.size() < 1) {
                    checkHotelGoodStatus(switchHotelUpVo.getHotelId());
                    can.add(switchHotelUpVo.getHotelId());
                } else {
                    for (MtHotelDownVo mtHotelDownVo : mtHotelDownVos) {
                        //0 下线  1 上线
                        if (mtHotelDownVo.getStatus() == 0) {
                            switchHotelUpMapper.updateHotelStatis(String.valueOf(switchHotelUpVo.getHotelId()), 0);
                        } else {
                            can.add(switchHotelUpVo.getHotelId());
                        }
                        checkHotelGoodStatus(switchHotelUpVo.getHotelId());
                    }
                }
            }
            List<List<Integer>> canHotelIds = ListUtils.parititon(can, 50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities = new ArrayList<>();
            if (canHotelIds.size() > 0) {
                for (List<Integer> list : canHotelIds) {
                    Integer[] hotelId = new Integer[list.size()];
                    Result<Object> result1 = pushHotelStatus(list.toArray(hotelId), 1);
                    if (result1.getCode() == CommonConstants.SUCCESS) {
                        switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","), 3);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer hotelIds : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(hotelIds);
                            switchHotelUpLogEntity.setUp(3);
                            switchHotelUpLogEntity.setUsername("system-全部售卖");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                    }
                    try {
                        Thread.sleep(9000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            if (switchHotelUpLogEntities.size() > 0) {
                switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
            }
            saveRedisCache(1);
            long endTime = System.currentTimeMillis();
            log.info("==========整体上架耗时时间为{}ms", (endTime - startTime));
        }
    }

    /**
     * 遍历酒店是否含有失效的产品
     */
    public void checkHotelGoodStatus(int hotelId) {
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(hotelId);
        String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_TEN_HOTELS_GOODS_FAILURE.getUrl();
        MtHotelGoodsCheckFailVo mtHotelGoodsCheckFailVo = new MtHotelGoodsCheckFailVo();
        List<MtHotelGoodsCheckFailOneVo> mtHotelGoodsCheckFailOneVos = new ArrayList<>();
        MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo = new MtHotelGoodsCheckFailOneVo();
        List<String> goodsIds = new ArrayList<>();
        int mtHotelId = 0;
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            goodsIds.add(String.valueOf(switchCreateRoomEntity.getMtGoodId()));
            mtHotelId = switchCreateRoomEntity.getMtHotelId();
        }
        mtHotelGoodsCheckFailOneVo.setGoodsIds(goodsIds);
        mtHotelGoodsCheckFailOneVo.setMtHotelId(String.valueOf(mtHotelId));
        mtHotelGoodsCheckFailOneVos.add(mtHotelGoodsCheckFailOneVo);
        mtHotelGoodsCheckFailVo.setHotels(mtHotelGoodsCheckFailOneVos);
        Result<List<MtHotelGoodsCheckFailOneVo>> result = switchRestTempaleUtilsService.sendReuestToMtCheckHotelGoodFailure(url, mtHotelGoodsCheckFailVo);
        List<MtHotelGoodsCheckFailOneVo> mtHotelGoodsCheckFailOneVos1 = result.getData();
        if (!ObjectUtils.isEmpty(mtHotelGoodsCheckFailOneVos1) && mtHotelGoodsCheckFailOneVos1.size() > 1) {
            for (MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo1 : mtHotelGoodsCheckFailOneVos1) {
                List<String> goodsId = mtHotelGoodsCheckFailOneVo1.getGoodsIds();
                if (goodsId.size() > 1) {
                    for (String goodId : goodsId) {
                        //1.推送携程接口，设置售卖无效
                        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectByMtGoodsIdAndHotelId(mtHotelId, Integer.valueOf(goodId));
                        if (!ObjectUtils.isEmpty(switchCreateRoomEntity)) {
                            SetRoomOnlineOfflineVo setRoomOnlineOfflineVo = new SetRoomOnlineOfflineVo();
                            setRoomOnlineOfflineVo.setRoomTypeId(switchCreateRoomEntity.getRoomId());
                            setRoomOnlineOfflineVo.setHotelId(switchCreateRoomEntity.getHotelId());
                            setRoomOnlineOfflineVo.setChannel("Ctrip");
                            setRoomOnlineOfflineVo.setRoomStatus(2);
                            Result<Object> results = switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                            setRoomOnlineOfflineVo.setChannel("Qunar");
                            switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                            //设置无效成功
                            if (result.getCode() == CommonConstants.SUCCESS) {
                                //2.添加到产品失效库
                                SwitchCreateRoomFailureEntity switchCreateRoomFailureEntity = new SwitchCreateRoomFailureEntity();
                                BeanUtils.copyProperties(switchCreateRoomEntity, switchCreateRoomFailureEntity);
                                switchCreateRoomFailureEntity.setId(switchCreateRoomFailureEntity.getId() + StringUtil.getFourRandom());
                                int flag = switchCreateRoomFailureMapper.insert(switchCreateRoomFailureEntity);
                                //3.从产品库删除
                                if (flag > 0) {
                                    switchCreateRoomMapper.deleteRoomInfoByMtHotelIdAndMtGoodId(mtHotelId, goodId);
                                    //4.从缓存中清除
                                    String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                                    redisService.remove(key);
                                    String key3 = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                                    if (redisService.exists(key3)) {
                                        redisService.remove(key3);
                                    }
                                }
                            }
                            try {
                           /*     Thread.sleep(6000);
                                setRoomOnlineOfflineVo.setChannel("ChannelA");
                                switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);*/
                                Thread.sleep(6000);
                                setRoomOnlineOfflineVo.setChannel("B2B");
                                switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        } else {
                            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
                        }
                    }
                }
            }
        }

    }

    /**
     * 遍历售卖房型
     *
     * @return
     */
    @Override
    public Result<Object> runHotel() {
        log.info("==========調用调用下单前校验更新携程,跑上架的酒店==========");
        long startTime = System.currentTimeMillis();
        //1.判断是否今日调用过上架接口
        String key = CommonConstants.SWITCH_PUSH_ROOM_THREAD_NUM;
        redisService.set(key, 3);
        int total = 50000;
        //上架的总售卖房型个数
        int num = switchHotelUpMapper.getRoomIdOfHotelNum();
        String upTime = "";
        if (!redisService.exists(SWITCH_HOTEL_UP_TIME)) {
            log.info("=======================没有酒店进行售卖，暂时不去调用美团下单效验接口====================================");
            return new Result<>("没有酒店进行售卖，暂时不去调用美团下单效验接口");
        }
        upTime = (String) redisService.get(SWITCH_HOTEL_UP_TIME);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String now = formatter.format(date);
        if (upTime.equals(now)) {
            total = total - num;
        }
        String check_num_key = "switch_call_mt_order_check_num";
        int useNum = 0;
        if (redisService.exists(check_num_key)) {
            useNum = (int) redisService.get(check_num_key);
        }
        if (useNum > total) {
            log.info("=======================调用美团下单效验接口次数已经用完了====================================");
            return new Result<>("用完了");
        }
        //获取遍历
        //   List<Integer> ids = switchHotelUpMapper.selectIds(1);
        List<Integer> ids = new ArrayList<>();
        List<List<Integer>> hotelIds = ListUtils.parititon(ids, 3);
        log.info("=======总共需要调用{}次=========", hotelIds.size());
        int times = 0;
        log.info("==========開始進行酒店遍歷===================");
        for (List<Integer> list : hotelIds) {
            Result<Object> result = execHotelUp(list);
            log.info("===================第{}次上架酒店，6s/次", times++);
        }
        long endTime = System.currentTimeMillis();
        redisService.set(key, 12);
        log.info("==========酒店遍歷完成,改為12個線程===================");
        useNum += num;
        redisService.set(check_num_key, useNum);
        log.info("==========整体上架耗时时间为{}ms", (endTime - startTime));
        return new Result<>();
    }
    /**
     * 批量上架
     */
    @SneakyThrows
    public Result<Object> execHotelUp(List<Integer> list) {
        ExecutorService executorServiceByHotel = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
        List<Future<Result<Object>>> futureList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (!executorServiceByHotel.isShutdown()) {
                Future<Result<Object>> future = executorServiceByHotel.submit(new switchHotelUp(list.get(i), "酒店线程" + list.get(i)));
                futureList.add(future);
                Thread.sleep(200);
            }

        }
        executorServiceByHotel.shutdown();
        while (true) {
            if (executorServiceByHotel.isTerminated()) {
                for (Future<Result<Object>> future : futureList) {
                    log.info("=====执行完毕,执行结果为{}======", future.get().getMsg());
                }
                break;
            }
        }
        return new Result<>();
    }

    /**
     * 上架前推送房态价格库存
     */
    @SneakyThrows
    public Result<Object> pushRoomPriceAndStatus(Integer hotelId) {
        ExecutorService executorService = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
        log.info("============酒店id为{}开始进行进行数据推送======", hotelId);
        //获取酒店的售卖房型id
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectHotelRoomId(hotelId);
        log.info("============酒店id为{}的售卖房型长度为{}=====", hotelId, switchCreateRoomEntities.size());
        List<Future<List<RoomDataEntityVo>>> futureList = new ArrayList<>();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
            if (!executorService.isShutdown()) {
                Future<List<RoomDataEntityVo>> future = executorService.submit(new MtHotelOrderChekck(switchCreateRoomEntity, "Thread" + hotelId));
                futureList.add(future);
            }
        }
        //关闭线程池，等线程后台执行
        executorService.shutdown();
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        Result<Map<String, String>> result;
        String msg = "";
        while (true) {
            if (executorService.isTerminated()) {
                for (Future<List<RoomDataEntityVo>> future : futureList) {
                    roomDataEntityVos.addAll(future.get());
                    log.info("=============线程返回的数据为{}", JSON.toJSONString(future.get()));
                    log.info("=============hotelId{}roomDataEntityVos添加完成了,长度为{},返回的数据为{}", hotelId, roomDataEntityVos.size(), future.get().size());
                }
                log.info("执行完毕,roomDataEntityVos的长度为{}", roomDataEntityVos.size());
                BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
                batchPushRoomVo.setHotelId(hotelId);
                batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
                if (roomDataEntityVos.size() > 0) {
                    log.info("============hotel的id为{}请求的json数据为{}=======", hotelId, JSON.toJSONString(batchPushRoomVo));
                    result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                    log.info("====================请求推送价格房态的接口返回的信息为{}============", result.getMsg());
                    msg = result.getMsg().toString();
                } else {
                    log.info("=======~~~~~~~~hotelId为{}数据为空~~~~~~无法调用携程推送价格房态接口================", hotelId);
                    msg = "没有调用接口";
                }
                break;
            }
        }
        List<Integer> liste = new ArrayList<>();
        liste.add(hotelId);
        log.info("============酒店id为{}执行完毕=====", hotelId);
        return new Result<>(msg);
    }

    /**
     * 多线程执行上架
     */
    class switchHotelUp implements Callable<Result<Object>> {
        Integer hotelId;
        String theadName;

        public switchHotelUp(Integer hotelId, String theadName) {
            this.hotelId = hotelId;
            this.theadName = theadName;
        }

        @Override
        public Result<Object> call() throws Exception {
            log.info("=============酒店id为{}开始调用pushRoomPriceAndStatus接口", this.hotelId);
            Result<Object> result = pushRoomPriceAndStatus(this.hotelId);
            log.info("=============酒店id为{}调用pushRoomPriceAndStatus接口结束", this.hotelId);
            return result;
        }
    }

    /**
     * 多线程调用下单前效验
     */
    class MtHotelOrderChekck implements Callable<List<RoomDataEntityVo>> {
        SwitchCreateRoomEntity switchCreateRoomEntity;
        String theadName;

        public MtHotelOrderChekck(SwitchCreateRoomEntity switchCreateRoomEntity, String theadName) {
            this.switchCreateRoomEntity = switchCreateRoomEntity;
            this.theadName = theadName;
        }

        @Override
        public List<RoomDataEntityVo> call() {
            List<RoomDataEntityVo> roomDataEntityVos = callMtCheckAssembleData(this.switchCreateRoomEntity);
            log.info("{}执行完毕,返回的数据为{}", theadName, JSON.toJSONString(roomDataEntityVos));
            return roomDataEntityVos;
        }
    }

    /**
     * @author: lmf
     * @time: 2020/10/13 15:33
     * 调用美团的下单前效验接口
     */
    public List<RoomDataEntityVo> callMtCheckAssembleData(SwitchCreateRoomEntity switchCreateRoomEntity) {
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.ORDER_CHECK.getUrl();
        map.put("hotelId", switchCreateRoomEntity.getMtHotelId());
        map.put("goodsId", switchCreateRoomEntity.getMtGoodId());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String now = formatter.format(date);
//        String startTimes= DateUtil.getNextDay(now);
        map.put("checkinDate", now);
        map.put("checkoutDate", DateUtil.getNextDay(now));
        map.put("roomNum", 1);
        map.put("totalPrice", 10000);
        long startTime = System.currentTimeMillis();
        MtOrderCheckVo mtOrderCheckVo = switchRestTempaleUtilsService.orderCheck(url, map);
        long endTime = System.currentTimeMillis();
        log.info("=============调用美团的下单前效验接口耗费时间为{}", (endTime - startTime));
        //携程
        RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
        roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        roomDataEntityVo.setStartDate(now);
        roomDataEntityVo.setEndDate(now);
        //去哪儿
        RoomDataEntityVo qunarRoomDataEntityVo = new RoomDataEntityVo();
        qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //b2b
        RoomDataEntityVo b2bRoomDataEntityVo = new RoomDataEntityVo();
        b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //channel
        RoomDataEntityVo channelRoomDataEntityVo = new RoomDataEntityVo();
        channelRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        String channelChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_CHANNEL_A.getName());
        //房态推送数据
        //库存推送数据
        if (mtOrderCheckVo.getCode() == MtHotelOrderCheckCodeEnums.SUCESS.getCode()) {
            List<PirceModelVo> pirceModelVos = mtOrderCheckVo.getPriceModels();
            //携程房价实体
            RoomPriceModelVo roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setCurrency("CNY");
            roomPriceModelVo.setChannel(channel);
            //去哪儿房价实体
            RoomPriceModelVo qunarModelVo = new RoomPriceModelVo();
            qunarModelVo.setCurrency("CNY");
            qunarModelVo.setChannel(QunarChannel);
            //b2b房价实体
            RoomPriceModelVo b2bModelVo = new RoomPriceModelVo();
            b2bModelVo.setCurrency("CNY");
            b2bModelVo.setChannel(b2bChannel);
            //channel房价实体
            RoomPriceModelVo channelModelVo = new RoomPriceModelVo();
            channelModelVo.setCurrency("CNY");
            channelModelVo.setChannel(channelChannel);
            for (PirceModelVo pirceModelVo : pirceModelVos) {
                //价格推送数据
                startTime = System.currentTimeMillis();
                log.info("=================获取酒店上架价格配置start===================");
                Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = switchPushRoomService.getOnlinePriceSet();
                endTime = System.currentTimeMillis();
                log.info("=================获取酒店上架价格配置end,耗费时间为{}===================", (endTime - startTime));
                //针对统一的进行价格公式计算
                Map<String, Object> priceMap = new HashMap<>();
                //判断是否参加促销活动
                startTime = System.currentTimeMillis();
                SwitchHotelActiveTagEntity switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), pirceModelVo.getDate());
                if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                    priceMap = switchPushRoomService.getPriceV2(priceSetMap, pirceModelVo.getSalePrice(), pirceModelVo.getSubPrice(), null);
                } else {
                    String currentWeekDay = DateUtil.dayForWeek(pirceModelVo.getDate());
                    //促销
                    if (!ObjectUtils.isEmpty(switchHotelActiveTagEntity)&&DateUtil.commpareDay(switchHotelActiveTagEntity.getStartTime(),pirceModelVo.getDate())&&DateUtil.commpareDay(pirceModelVo.getDate(),switchHotelActiveTagEntity.getEndTime())) {
                        priceMap = switchPushRoomService.getPriceV2(priceSetMap, pirceModelVo.getSalePrice(), pirceModelVo.getSubPrice(), switchHotelActiveTagEntity);
                    } else {//判断当前周几，是否符合促销活动
                        priceMap = switchPushRoomService.getPriceV2(priceSetMap, pirceModelVo.getSalePrice(), pirceModelVo.getSubPrice(), null);
                    }
                }
                endTime = System.currentTimeMillis();
                log.info("==========计算价格公式所耗费时间为{}", (endTime - startTime));
                //如果价格符合公式，房态可预定 有库存就进行设置推送
                double price = Double.parseDouble(priceMap.get("ctripPrice").toString());
                double channelPrice = Double.parseDouble(priceMap.get("qunarPrice").toString());
                roomPriceModelVo.setRoomPrice(price);
                qunarModelVo.setRoomPrice(channelPrice);
                b2bModelVo.setRoomPrice(channelPrice);
                channelModelVo.setRoomPrice(channelPrice);
                roomDataEntityVo.setStartDate(pirceModelVo.getDate());
                roomDataEntityVo.setEndDate(pirceModelVo.getDate());
                roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
                qunarRoomDataEntityVo.setStartDate(pirceModelVo.getDate());
                qunarRoomDataEntityVo.setEndDate(pirceModelVo.getDate());
                qunarRoomDataEntityVo.setRoomPriceModel(qunarModelVo);
                b2bRoomDataEntityVo.setStartDate(pirceModelVo.getDate());
                b2bRoomDataEntityVo.setEndDate(pirceModelVo.getDate());
                b2bRoomDataEntityVo.setRoomPriceModel(b2bModelVo);
                channelRoomDataEntityVo.setStartDate(pirceModelVo.getDate());
                channelRoomDataEntityVo.setEndDate(pirceModelVo.getDate());
                channelRoomDataEntityVo.setRoomPriceModel(channelModelVo);
                //携程房态推送实体
                RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
                roomStatusModelVo.setChannel(channel);
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                //去哪儿房态
                RoomStatusModelVo qunarRoomStatusModelVo = new RoomStatusModelVo();
                qunarRoomStatusModelVo.setChannel(QunarChannel);
                qunarRoomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                qunarRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                //b2b房态
                RoomStatusModelVo b2bRoomStatusModelVo = new RoomStatusModelVo();
                b2bRoomStatusModelVo.setChannel(b2bChannel);
                b2bRoomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                b2bRoomDataEntityVo.setRoomStatusModel(b2bRoomStatusModelVo);
                //channels
                RoomStatusModelVo channleRoomStatusModelVo = new RoomStatusModelVo();
                channleRoomStatusModelVo.setChannel(channelChannel);
                channleRoomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                channelRoomDataEntityVo.setRoomStatusModel(b2bRoomStatusModelVo);

                //库存推送实体
                RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(channel);
                roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPreservedQuantity(0);
                roomInventoryModelVo.setUnPreservedQuantity(1);
                roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                roomDataEntityVos.add(roomDataEntityVo);
                roomDataEntityVos.add(qunarRoomDataEntityVo);
                roomDataEntityVos.add(b2bRoomDataEntityVo);
                roomDataEntityVos.add(channelRoomDataEntityVo);
            }
        } else {
            //房态推送实体
            RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
            roomStatusModelVo.setChannel(channel);
            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
            roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
            //库存推送实体
            RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
            roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
            roomInventoryModelVo.setChannel(channel);
            roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
            roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
            roomInventoryModelVo.setPreservedQuantity(0);
            roomInventoryModelVo.setUnPreservedQuantity(1);
            roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
            roomDataEntityVos.add(roomDataEntityVo);
        }
        log.info("结果数据为{}", roomDataEntityVos.size());
        return roomDataEntityVos;
    }

    /***
     * @Author: lmf
     * @Date: 2020/10/6
     * 推送价格房态
     */
    public void pushData(Integer hotelId) {
        //先调用爬虫,爬取房态如果失败就手动去拉
        String url = CommonUrlConstants.SPIDER_HOST + "/meituanSpider/meituanSpiderHotelGoodsNoticeByMtHotelRoom";
        Map<String, List<String>> map = new HashMap<>();
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(hotelId);
        List<String> list = new ArrayList<>();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            list.add(String.valueOf(switchCreateRoomEntity.getMtGoodId()));
            map.put(String.valueOf(switchCreateRoomEntity.getMtHotelId()), list);
            try {
                Thread.sleep(6000);
                Result result1 = switchPushRoomService.retryPushRoomData(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), 1);
                if (result1.getCode() == CommonConstants.SUCCESS) {
                    Result result = RestTemplateUtils.post(url, JacksonUtil.objectToJson(map), restTemplate);
                    //如果调用爬虫接口失败,重新调用
                    if (result.getCode() == CommonConstants.ERROR) {
                        //如果调用爬虫接口失败,重新调用
                        RestTemplateUtils.post(url, JacksonUtil.objectToJson(map), restTemplate);
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    class PushTRoomhread implements Runnable {
        private Integer hotelId;

        public PushTRoomhread(Integer hotelId) {
            this.hotelId = hotelId;
        }

        @Override
        public void run() {
            pushData(hotelId);
        }
    }

    class PushThread implements Runnable {
        private List<Integer> id;
        private int status;

        public PushThread(List<Integer> id, int status) {
            this.id = id;
            this.status = status;
        }

        @Override
        public void run() {
            saveRedisCache(status);
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/24
     */
    public void saveRedisCache(int status) {
        log.info("==============酒店的状态{}==================", status);
        //上线售卖
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = new ArrayList<>();
        if (status == 1) {
            switchCreateRoomEntities = switchCreateRoomMapper.selectHotelUpStatus(3);
            for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                //清除与售卖房型的关联数据
                String key = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //添加美团酒店id+美团产品id的key
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                redisService.set(key, switchCreateRoomEntity.getMtRoomId());
                //添加美团酒店id+美团房型id
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
                redisService.set(key, "1");
                //添加美团酒店id+美团产品id+餐食
                if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")) {
                    redisService.set(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + "_0", 0);
                } else if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("640292")) {
                    redisService.set(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + "_1", 2);
                } else {
                    redisService.set(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + "_1", switchCreateRoomEntity.getMealCount());
                }
            }
        } else {
            switchCreateRoomEntities = switchCreateRoomMapper.selectHotelUpStatus(2);
            for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                //清除与售卖房型的关联数据
                String key = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //清除美团酒店id+美团产品id的key
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //清除美团酒店id+美团房型id
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //清除美团酒店id+美团产品id+餐食
                key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_0";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
            }
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 修改酒店上下线状态
     */
    @Override
    public Result<Object> modifyHotelStatus(SetHotelUpVo setHotelUpVo) {
        int status = 1;
        if (setHotelUpVo.getStatus() == 0 ) {
            status = 0;
        }else if(setHotelUpVo.getStatus()==1){
            status=2;
        }

        Integer[] ids = new Integer[]{setHotelUpVo.getHotelId()};
        Result<Object> result;
        //黑名单的话直接下架
        if (setHotelUpVo.getStatus() == 2) {
            //saveRedisCache(0);
            result = pushHotelStatusByBlack(ids);
        } else {
            result = pushHotelStatus(ids, status);
        }
        List<Integer> list = new ArrayList<>();
        list.add(setHotelUpVo.getHotelId());
        if (result.getCode() == CommonConstants.SUCCESS) {
            int flag = switchHotelUpMapper.updateHotelSaleStatus(setHotelUpVo.getHotelId(), (setHotelUpVo.getStatus()==0)?4:setHotelUpVo.getStatus());
            //如果是上架就调用下单前效验
            if (status == 1) {
                Integer mtHotelId = switchHotelUpMapper.selectMtHotelIdByHotelId(setHotelUpVo.getHotelId());
                if (!ObjectUtils.isEmpty(mtHotelId)) {
                    redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,mtHotelId);
                    Integer[] hotelId = new Integer[1];
                    hotelId[0] = mtHotelId;
                    String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_HOTEL_FAILURE.getUrl();
                    Map<String, Object> params = new HashMap<>();
                    params.put("hotelIds", hotelId);
                    Result<List<MtHotelDownVo>> result2 = switchRestTempaleUtilsService.sendReuestToMtCheckHotelFailure(url, params);
                    List<MtHotelDownVo> mtHotelDownVos = result2.getData();
                    //调用美团接口检查是否有被拉入黑名单的酒店
                    if (mtHotelDownVos.size() < 1) {
                        checkHotelGoodStatus(setHotelUpVo.getHotelId());
                    } else {
                        for (MtHotelDownVo mtHotelDownVo : mtHotelDownVos) {
                            //0 下线  1 上线
                            if (mtHotelDownVo.getStatus() == 0) {
                                switchHotelUpMapper.updateHotelStatis(String.valueOf(setHotelUpVo.getHotelId()), 0);
                            }
                            checkHotelGoodStatus(setHotelUpVo.getHotelId());
                        }
                    }
                }
                //添加操作日志
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(1);
                switchHotelUpLogEntity.setHotelId(setHotelUpVo.getHotelId());
                switchHotelUpLogEntity.setUp(setHotelUpVo.getStatus());
                switchHotelUpLogEntity.setUsername("admin-后台操作");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
            } else {
                Integer mtHotelId = switchHotelUpMapper.selectMtHotelIdByHotelId(setHotelUpVo.getHotelId());
                if(!ObjectUtils.isEmpty(mtHotelId)){
                    redisService.removeSetElt(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,mtHotelId);
                }
                //添加操作日志
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(1);
                switchHotelUpLogEntity.setHotelId(setHotelUpVo.getHotelId());
                switchHotelUpLogEntity.setUp(setHotelUpVo.getStatus());
                switchHotelUpLogEntity.setUsername("admin-后台操作");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
            }
            if (flag > 0) {
                return new Result<>(CommonConstants.SUCCESS, "操作成功");
            } else {
                return new Result<>("操作失败");
            }
        } else {
            return new Result<>("操作失败");
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 获取上架所有数据
     * @param getRoomListVo
     */
    @Override
    public Result<Object> getHotelList(GetRoomListVo getRoomListVo) {
        PageHelper.startPage(getRoomListVo.getPageCode(), getRoomListVo.getPageSize());
        List<SwitchHotelUpEntity> list = switchHotelUpMapper.selectByHotelName(getRoomListVo.getHotelName());
        PageInfo<SwitchHotelUpEntity> pageInfo = new PageInfo<>(list);
        return new Result<>(pageInfo);
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 导入execel到数据库中
     */
    @Override
    public Result<Object> upExecel(MultipartFile excelFile) {
        List<SwitchHotelUpEntity> switchHotelUpEntities = new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            tab:
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(0);
                cell.setCellType(CellType.STRING);
                cell = sheetRow.getCell(0);
                String hotelName = cell.getStringCellValue();
                cell = sheetRow.getCell(1);
                Double masterHotelId = cell.getNumericCellValue();
                cell = sheetRow.getCell(2);
                Double hotelId = cell.getNumericCellValue();
                SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectByHotelId(hotelId.intValue());
                if (!ObjectUtil.isEmpty(switchHotelUpEntity)) {
                    continue tab;
                }
                switchHotelUpEntity = new SwitchHotelUpEntity();
                switchHotelUpEntity.setId(StringUtil.getUUID());
                switchHotelUpEntity.setHotelId(hotelId.intValue());
                switchHotelUpEntity.setHotelName(hotelName);
                switchHotelUpEntity.setUp(0);
                switchHotelUpEntity.setCreateTime(new Date());
                switchHotelUpEntity.setRemark("");
                switchHotelUpEntity.setMasterHotelId(masterHotelId.intValue());
                switchHotelUpEntities.add(switchHotelUpEntity);
            }
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        if (switchHotelUpEntities.size() > 0) {
            int result = switchHotelUpMapper.insertList(switchHotelUpEntities);
            if (result > 0) {
                return new Result<>();
            } else {
                return new Result<>("导入失败");
            }
        } else {
            return new Result<>("导入失败");
        }
    }

    /***
     * @Author: lmf
     * @Date: 2021/2/2
     * 主动查询价格，获取在售的酒店列表
     */
    @Override
    public Result<Object> getUpHotelAsc() {
        List<Integer> list = switchHotelUpMapper.getUpHotelAsc();
        if(redisService.exists("is_open_four_hotel_list")){
            int size=40000-list.size();
            List<Integer> replaceList=switchHotelUpMapper.replaceList();
            for(int i=0;i<size;i++){
                Integer mtHotelId=replaceList.stream().findFirst().orElse(null);
                list.add(mtHotelId);
                replaceList.remove(mtHotelId);
            }
        }
       /* if(redisService.exists(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST)){
            redisService.remove(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST);
        }
        list.forEach(e->{
            redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,e);
        });*/
        return new Result<>(GsonUtils.GsonString(list), "success");
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 设置酒店的售卖状态  携程关闭各渠道在售
     */
    public Result<Object> pushHotelStatus(Integer[] hotelIds, int status) {
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", hotelIds);
        if(status==2){
            updateChannelVoMap.put("cBookable", 0);
        }else{
            updateChannelVoMap.put("cBookable", status);
        }
        if(status==0){
            updateChannelVoMap.put("qBookable", 0);
            updateChannelVoMap.put("channelABookable", 0);
            updateChannelVoMap.put("b2bBookable", 0);
        }else{
            updateChannelVoMap.put("qBookable", 1);
            updateChannelVoMap.put("channelABookable", 1);
            updateChannelVoMap.put("b2bBookable", 1);
        }
        return switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 设置酒店各渠道统一上下线
     */
    public Result<Object> setHotelStatus(Integer[] hotelIds, int status) {
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", hotelIds);
        updateChannelVoMap.put("cBookable", status);
        updateChannelVoMap.put("qBookable", status);
        updateChannelVoMap.put("channelABookable", status);
        updateChannelVoMap.put("b2bBookable", status);
        return switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
    }

    /**
     * @author: lmf
     * @time: 2020/11/6 10:03
     * 设置酒店房型推送 针对黑名单的直接下架
     */
    public Result<Object> pushHotelStatusByBlack(Integer[] hotelIds) {
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", hotelIds);
        updateChannelVoMap.put("cBookable", 0);
        updateChannelVoMap.put("qBookable", 0);
        updateChannelVoMap.put("channelABookable", 0);
        updateChannelVoMap.put("b2bBookable", 0);
        return switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
    }

    /**
     * @author: lmf
     * @time: 2020/10/27 16:39
     * 导入酒店数据,开启酒店售卖
     */
    @SneakyThrows
    @Override
    public Result<Object> submitUploadSale(MultipartFile excelFile, Integer status) {
        List<Integer> can = new ArrayList<>();
        List<Integer> black = new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(1);
                Double hotelId = cell.getNumericCellValue();
                log.info("=======共有表格数据长度为{}===", sheet.getPhysicalNumberOfRows());
                Example example = new Example(SwitchHotelUpEntity.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("hotelId", hotelId.intValue());
                //黑名单的酒店不进行创建,不存在上架表的不创建
                SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectOneByExample(example);
                log.info("=====switchHotelUpEntity的值为{}",switchHotelUpEntity.toString());
                if (switchHotelUpEntity.getUp() != 2&&switchHotelUpEntity.getUp() != 0&&switchHotelUpEntity.getStatus()!=2) {
                    can.add(hotelId.intValue());
                   /* ExecutorService executorService = Executors.newFixedThreadPool(1);
                    executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                    executorService.shutdown();
                    Thread.sleep(300);*/
                } else if (switchHotelUpEntity.getUp() == 2) {
                    black.add(hotelId.intValue());
                }else if(switchHotelUpEntity.getUp() == 0){
                    SwitchHotelUpLogEntity switchHotelUpLogEntity=new SwitchHotelUpLogEntity();
                    switchHotelUpLogEntity.setUp(0);
                    switchHotelUpLogEntity.setHotelId(hotelId.intValue());
                    switchHotelUpLogEntity.setUsername("admin批量导入-酒店下线");
                    switchHotelUpLogEntity.setCreateTime(new Date());
                    switchHotelUpLogEntity.setGenre(1);
                    switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                    if(switchHotelUpEntity.getStatus()!=4){
                        switchHotelUpEntity=new SwitchHotelUpEntity();
                        switchHotelUpEntity.setStatus(3);
                        switchHotelUpEntity.setModifyTime(new Date());
                        switchHotelUpMapper.updateByExampleSelective(switchHotelUpEntity,example);
                    }
                }

            }
            log.info("========上架前可循环一次所有上架酒店,目前有{}个酒店====", can.size());
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        log.info("========上架前可循环一次所有上架酒店,目前有{}个酒店====", can.size());
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(new submitSaleThread(can, black));
        executorService.shutdown();

        return new Result<>();

    }

    class submitSaleThread implements Runnable {
        List<Integer> can;
        List<Integer> black;

        public submitSaleThread(List<Integer> can, List<Integer> black) {
            this.can = can;
            this.black = black;
        }

        @Override
        public void run() {
            List<List<Integer>> canHotelIds = ListUtils.parititon(can, 50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities = new ArrayList<>();
            if (canHotelIds.size() > 0) {
                for (List<Integer> list : canHotelIds) {
                    Integer[] hotelId = new Integer[list.size()];
                    Result<Object> result1 = pushHotelStatus(list.toArray(hotelId), 1);
                    if (result1.getCode() == CommonConstants.SUCCESS) {
                        switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","), 3);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(3);
                            switchHotelUpLogEntity.setUsername("admin-批量导入售卖");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                            redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,id);
                        }
                    }else if(result1.getMsg().toString().contains("频率")){
                        try {
                            Thread.sleep(6000);
                            result1=pushHotelStatus(list.toArray(hotelId), 1);
                            switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","), 3);
                            SwitchHotelUpLogEntity switchHotelUpLogEntity;
                            for (Integer id : list) {
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(id);
                                switchHotelUpLogEntity.setUp(3);
                                switchHotelUpLogEntity.setUsername("admin-批量导入售卖"+result1.getMsg());
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                                redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,id);
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else if(result1.getMsg().toString().contains("MIPHotel")){
                        switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","), 3);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(3);
                            switchHotelUpLogEntity.setUsername("admin-批量导入售卖"+result1.getMsg());
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                    }
                    try {
                        Thread.sleep(8000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            if (switchHotelUpLogEntities.size() > 0) {
                switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                saveRedisCache(1);
            }
            if (black.size() > 1) {
                List<List<Integer>> blackHotelIds = ListUtils.parititon(black, 50);
                if (canHotelIds.size() > 0) {
                    for (List<Integer> list : blackHotelIds) {
                        Integer[] hotelId = new Integer[list.size()];
                        //保存缓存
                        //saveRedisCache(list, 1);
                        Map<String, Object> updateChannelVoMap = new HashMap<>();
                        updateChannelVoMap.put("hotelIDs", hotelId);
                        updateChannelVoMap.put("cBookable", 0);
                        updateChannelVoMap.put("qBookable", 0);
                        updateChannelVoMap.put("channelABookable", 0);
                        updateChannelVoMap.put("b2bBookable", 0);
                        Result<Object> result=switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                        if(result.getMsg().toString().contains("执行频率过快")){
                            try {
                                Thread.sleep(2000);
                                switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(2);
                            switchHotelUpLogEntity.setUsername("admin-批量导入售卖-记录黑名单");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                        try {
                            Thread.sleep(8000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            if (redisService.exists("every_week_reset_up_hotel_data")) {
                Example example = new Example(SwitchHotelUpEntity.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("up", 1);
                List<SwitchHotelUpEntity> switchHotelUpEntities = switchHotelUpMapper.selectByExample(example);
                List<Integer> down = new ArrayList<>();
                for (SwitchHotelUpEntity switchHotelUpEntity : switchHotelUpEntities) {
                    down.add(switchHotelUpEntity.getHotelId());
                }
                List<List<Integer>> downcHotelIds = ListUtils.parititon(down, 50);
                if (canHotelIds.size() > 0) {
                    for (List<Integer> list : downcHotelIds) {
                        Integer[] hotelId = new Integer[list.size()];
                        pushHotelStatus(list.toArray(hotelId), 0);
                        try {
                            Thread.sleep(6000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    @Override
    public Result<Object> getUpHotelGoodsDataForBasicRoom() {
        List<SwitchCreateRoomDto> list = null;
        if (null != redisService.get(MeituanConstants.REDIS_BASIC_SOME_HOTELS_TEST)) {
            Map map = new HashMap();
            map.put("mtHotelId", redisService.get(MeituanConstants.REDIS_BASIC_SOME_HOTELS_TEST));
            list = switchHotelUpMapper.getUpHotelGoodsDataByMap(map);
        } else {
            list = switchHotelUpMapper.getUpHotelGoodsData();
        }
        return new Result(GsonUtils.GsonString(list), "success");
    }
    @Override
    public Result<Object> getUpHotelGoodsData() {
        List<SwitchCreateRoomDto> list = switchHotelUpMapper.getUpHotelGoodsData();
        return new Result(GsonUtils.GsonString(list), "success");
    }

    @Override
    public Result<Object> getUpHotelGoodsDataByHotelId(Integer mtHotelId) {
        Map map = new HashMap();
        map.put("mtHotelId", mtHotelId);
        List<SwitchCreateRoomDto> list = switchHotelUpMapper.getUpHotelGoodsDataByHotelId(map);
        return new Result(GsonUtils.GsonString(list), "success");
    }
    @Override
    public Result<List<CompareRoomForFpVO>> getUpHotelGoodsDataFp() {
        List<CompareRoomForFpVO> roomList = switchHotelUpMapper.getUpHotelGoodsDataFp();
        return new Result<>(roomList);
    }

    /**
     * 添加所有酒店的缓存
     *
     * @return
     */
    public Result<Object> addHotel() {
        List<SwitchCreateSubHotelEntity> switchCreateSubHotelEntities = switchCreateSubHotelMapper.selectAll();
        for (SwitchCreateSubHotelEntity switchCreateSubHotelEntity : switchCreateSubHotelEntities) {
            //先获取美团的id
            String mtHotelId = "";
            Map<String, String> params = new HashMap<>();
            params.put("masterHotelId", String.valueOf(switchCreateSubHotelEntity.getMasterHotelId()));
            String url = CommonUrlConstants.COMPARE_HOST + "/" + CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
            Result result;
            try {
                result = switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url, params);
                if (result.getCode() == CommonConstants.SUCCESS) {
                    mtHotelId = result.getData().toString();
                    log.info("==========美团的酒店id为============{}", mtHotelId);
                    String keys=MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS + mtHotelId;
                    if(redisService.exists(keys)){
                        redisService.remove(keys);
                    }
                    /*redisService.set(MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS + mtHotelId, 1);*/
                }
            } catch (Exception e) {
                log.info("=======获取美团酒店id出现异常==============");
            }
        }
        List<SwitchHotelUpEntity> switchHotelUps = switchHotelUpMapper.selectAll();
        for (SwitchHotelUpEntity switchHotelUpEntity : switchHotelUps) {
            //先获取美团的id
            String mtHotelId = "";
            Map<String, String> params = new HashMap<>();
            params.put("masterHotelId", String.valueOf(switchHotelUpEntity.getMasterHotelId()));
            String url = CommonUrlConstants.COMPARE_HOST + "/" + CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
            Result result;
            try {
                result = switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url, params);
                if (result.getCode() == CommonConstants.SUCCESS) {
                    mtHotelId = result.getData().toString();
                    log.info("==========美团的酒店id为============{}", mtHotelId);
                    String keys=MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS + mtHotelId;
                    if(redisService.exists(keys)){
                        redisService.remove(keys);
                    }
                    /* redisService.set(MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS + mtHotelId, 1);*/
                }
            } catch (Exception e) {
                log.info("=======获取美团酒店id出现异常==============");
            }
        }
        return null;
    }

    /**
     * 添加美团的房型到缓存中key:mt_hotel_id+mt_room_id 作为效验房型是否失效的凭证
     *
     * @return
     */
    public Result<Object> addHotelRoomCache() {
        List<SwitchCreateRoomFailureEntity> switchCreateRoomFailureEntities = switchCreateRoomFailureMapper.selectAll();
        for(SwitchCreateRoomFailureEntity switchCreateRoomFailureEntity:switchCreateRoomFailureEntities){
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomFailureEntity.getMtHotelId() + "_" + switchCreateRoomFailureEntity.getMtRoomId();
            if(redisService.exists(key)){
                redisService.remove(key);
                log.info("=======效验房型是否失效的凭证旧缓存删除新缓存加入,产品id{}",switchCreateRoomFailureEntity.getMtGoodId());
            }
        }
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
            /*redisService.set(key, "1");*/
            if(redisService.exists(key)){
                redisService.remove(key);
            }
            log.info("=======效验房型是否失效的凭证旧缓存删除新缓存加入,产品id{}",switchCreateRoomEntity.getMtGoodId());
            redisService.hmSet(CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId(),"1");
        }
        return new Result<>();
    }

    /**
     * 添加美团的房型到缓存中key:mt_hotel_id+mt_good_id+餐食 作为效验餐食是否失效的凭证
     *
     * @return
     */
    public Result<Object> addHotelGoodBreakfastCache() {
        List<SwitchCreateRoomFailureEntity> switchCreateRoomFailureEntities = switchCreateRoomFailureMapper.selectAll();
        for (SwitchCreateRoomFailureEntity switchCreateRoomEntity : switchCreateRoomFailureEntities) {
            String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
            if (redisService.exists(key)) {
                redisService.remove(key);
            }
            String key2 = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_0";
            if (redisService.exists(key2)) {
                redisService.remove(key2);
            }
        }
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")) {
                String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_0";
                if(redisService.exists(key)){
                    redisService.remove(key);
                    key=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_0";
                    redisService.remove(key);
                }
                redisService.hmSet(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId(),0);
                log.info("=======餐食旧缓存删除新缓存加入,产品id{}",switchCreateRoomEntity.getMtGoodId());
            } else if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("640292")) {
                String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                if(redisService.exists(key)){
                    redisService.remove(key);
                    key=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
                    redisService.remove(key);
                }
                redisService.hmSet(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId(),2);
                log.info("=======餐食旧缓存删除新缓存加入,产品id{}",switchCreateRoomEntity.getMtGoodId());
            } else {
                String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                if(redisService.exists(key)){
                    redisService.remove(key);
                    key=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
                    redisService.remove(key);
                }
                redisService.hmSet(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId(),switchCreateRoomEntity.getMealCount());
                log.info("=======餐食旧缓存删除新缓存加入,产品id{}",switchCreateRoomEntity.getMtGoodId());
            }

        }
        return new Result<>();
    }

    public Result<Object> addHotelGoodCache() {
        List<SwitchCreateRoomFailureEntity> switchCreateRoomFailureEntities = switchCreateRoomFailureMapper.selectAll();
        for(SwitchCreateRoomFailureEntity switchCreateRoomFailureEntity:switchCreateRoomFailureEntities){
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomFailureEntity.getMtHotelId() + "_" + switchCreateRoomFailureEntity.getMtGoodId();
            if(redisService.exists(key)){
                redisService.remove(key);
                log.info("=======效验房型是否失效的凭证旧缓存删除新缓存加入,产品id{}",switchCreateRoomFailureEntity.getMtGoodId());
            }
        }
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            if(redisService.exists(key)){
                redisService.remove(key);
                log.info("=======房型旧缓存删除新缓存加入,产品id{}",switchCreateRoomEntity.getMtGoodId());
            }
            redisService.hmSet(CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId(),switchCreateRoomEntity.getMtRoomId());
        }
        return new Result<>();
    }

    /**
     * 添加酒店相关的缓存
     *
     * @return
     */
    @Override
    public Result<Object> addAllCache(Integer genre) {
        if (genre == 4) {
            //4.美团酒店id+美团产品id+餐食类型,value:餐食数量
            addHotelGoodBreakfastCache();
        } else if (genre == 1) {
            /* redisService.remove("goods_query_job_up_hotel_data");*/
            //1.酒店缓存
            addHotel();
        } else if (genre == 2) {
            //2.美团酒店id+美团产品id,value:为美团房型id
            addHotelGoodCache();
        } else if (genre == 3) {
            //3.美团酒店id+美团房型id
            addHotelRoomCache();
        } else {
            //1.酒店缓存
            redisService.remove("goods_query_job_up_hotel_data");
            addHotel();
            //2.美团酒店id+美团产品id,value:为美团房型id
            addHotelGoodCache();
            //3.美团酒店id+美团房型id
            addHotelRoomCache();

            //4.美团酒店id+美团产品id+餐食类型,value:餐食数量
            addHotelGoodBreakfastCache();
        }
        return new Result<>();
    }

    /**
     * @author: lmf
     * @date: 2020/8/14 13:45
     * 设置携程酒店下线
     */
    @Override
    public Result<Object> downHotel(SetHotelOnlineVo setHotelOnlineVo) {
        log.info("====================美团的酒店上下线请求数据为{}===========", JSON.toJSONString(setHotelOnlineVo));
        //如果美团的酒店对应的携程暂时没有添加
        //先获取美团的id
        Integer hotelId = switchCreateRoomMapper.getHotelIdByMtHotelId(setHotelOnlineVo.getMtHotelId());
        if (ObjectUtils.isEmpty(hotelId)) {
            Map<String,String> params=new HashMap<>();
            params.put("mtHotelId", String.valueOf(setHotelOnlineVo.getMtHotelId()));
            String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_HOTEL_ID.getUrl();
            Result<Integer> result;
            try {
                result= switchRestTempaleUtilsService.sendPOstRequestByGetHotelId(url,params);
                if(result.getCode()==CommonConstants.SUCCESS){
                    hotelId=result.getData();
                    log.info("==========携程的酒店id为============{}",hotelId);
                }else{
                    log.debug("============a美团的酒店id为{}，无对应的酒店数据", setHotelOnlineVo.getMtHotelId());
                    return new Result<>();
                }
            }catch (Exception e){
                log.debug("============asad美团的酒店id为{}，无对应的酒店数据", setHotelOnlineVo.getMtHotelId());
                return new Result<>();
            }
        }
        if (setHotelOnlineVo.getStatus() == 1) {
            //判断是否在黑名单里
            SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectByHotelId(hotelId);
            //黑名单的酒店不自动开起来
            if (!ObjectUtil.isEmpty(switchHotelUpEntity) && switchHotelUpEntity.getUp() == 2||switchHotelUpEntity.getStatus()==2) {
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(2);
                switchHotelUpLogEntity.setHotelId(hotelId);
                switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                switchHotelUpLogEntity.setUsername("system-黑名单酒店仅记录不上线");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                return new Result<>();
            } else {
                if (ObjectUtils.isEmpty(hotelId)) {
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                    switchHotelUpLogEntity.setCreateTime(new Date());
                    switchHotelUpLogEntity.setGenre(2);
                    switchHotelUpLogEntity.setHotelId(setHotelOnlineVo.getMtHotelId());
                    switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                    switchHotelUpLogEntity.setUsername("system-美团酒店id对应酒店携程id无售卖房型/映射");
                    switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                    return new Result<>("开启上线成功");
                } else {
                    Map<String, Object> updateChannelVoMap = new HashMap<>();
                    updateChannelVoMap.put("hotelIDs", new int[]{hotelId});
                    int up=1;
                    if(switchHotelUpEntity.getStatus()==3){
                        up=3;
                        updateChannelVoMap.put("cBookable", setHotelOnlineVo.getStatus());
                    }else{
                        updateChannelVoMap.put("cBookable", 0);
                    }
                    updateChannelVoMap.put("qBookable", 5);
                    updateChannelVoMap.put("channelABookable",5);//默认停售
                    updateChannelVoMap.put("b2bBookable", 5);//默认停售
                    Result<Object> setHotelSupplierBookableResult = switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                    if (setHotelSupplierBookableResult.getCode() == CommonConstants.SUCCESS) {
                        List<Integer> list = new ArrayList<>();
                        list.add(hotelId);
                        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectById(list);
                        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
                            String key2 = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
                            redisService.set(key2, 1);
                            //早餐缓存498160
                            if(switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")){
                                key2=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+ switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId()+"_0";
                                redisService.set(key2,0);
                            }else{
                                key2=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+ switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId()+"_1";
                                redisService.set(key2,switchCreateRoomEntity.getMealCount());
                            }
                        }
                        redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,hotelId);
                        //lmf
                        switchHotelUpMapper.updateHotelStatus(hotelId, up);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(2);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                        switchHotelUpLogEntity.setUsername("system-美团调用接口");
                        switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                        //开启上线
                        pushRoomPriceAndStatus(hotelId);
                    }
                    return setHotelSupplierBookableResult;
                }
            }
        } else {
            Map<String, Object> updateChannelVoMap = new HashMap<>();
            updateChannelVoMap.put("hotelIDs", new int[]{hotelId});
            updateChannelVoMap.put("cBookable", setHotelOnlineVo.getStatus());
            updateChannelVoMap.put("qBookable", setHotelOnlineVo.getStatus());
            updateChannelVoMap.put("channelABookable", setHotelOnlineVo.getStatus());//默认停售
            updateChannelVoMap.put("b2bBookable", setHotelOnlineVo.getStatus());//默认停售
            Result<Object> setHotelSupplierBookableResult = switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
            if (setHotelSupplierBookableResult.getCode() == CommonConstants.SUCCESS) {
                List<Integer> list = new ArrayList<>();
                list.add(hotelId);
                List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectById(list);
                for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                    String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                    if (redisService.exists(key)) {
                        redisService.remove(key);
                    }
                }
                switchHotelUpMapper.updateHotelStatus(hotelId, 0);
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(2);
                switchHotelUpLogEntity.setHotelId(hotelId);
                switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                switchHotelUpLogEntity.setUsername("system");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                redisService.removeSetElt(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,hotelId);
            }
            return setHotelSupplierBookableResult;
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/8
     * 批量更新售卖房型房态价格
     */
    @SneakyThrows
    @Override
    public Result<Object> batchUpdateRoomPriceAndStatus() {
        Example example = new Example(SwitchHotelUpEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("up", 3);
        List<SwitchHotelUpEntity> switchHotelUpEntities = switchHotelUpMapper.selectByExample(example);
        List<List<SwitchHotelUpEntity>> lists = ListUtils.parititon(switchHotelUpEntities, 8);
        List<Integer> hotelIds=new ArrayList<>();

        for (List<SwitchHotelUpEntity> switchHotelUpEntityList : lists) {
            ExecutorService executorService = Executors.newFixedThreadPool(8);
            List<Future<Result<Integer>>> futureList=new ArrayList<>();
            List<SwitchPushRoomLogEntity> switchPushRoomLogEntities=new ArrayList<>();
            for (SwitchHotelUpEntity switchHotelUpEntity : switchHotelUpEntityList) {
                Future<Result<Integer>> future=executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                futureList.add(future);
                Thread.sleep(200);
            }
            executorService.shutdown();
            SwitchPushRoomLogEntity switchPushRoomLogEntity;
            //进行下一步
            while(true){
                if(executorService.isTerminated()){
                    for(Future<Result<Integer>> future:futureList){
                        Result<Integer> result=future.get();
                        log.info("========当前的结果为{}============",result.getData());
                        if(result.getData()!=0){
                            switchPushRoomLogEntity=new SwitchPushRoomLogEntity();
                            hotelIds.add(result.getData());
                            switchPushRoomLogEntity.setHotelId(result.getData());
                            switchPushRoomLogEntity.setCreateTime(new Date());
                            switchPushRoomLogEntities.add(switchPushRoomLogEntity);
                        }
                    }
                    break;
                }
            }
            if(switchPushRoomLogEntities.size()>0){
                switchPushRoomLogMapper.insertList(switchPushRoomLogEntities);
            }
        }
        return new Result<>();
    }


    /***
     * @Author: lmf
     * @Date: 2020/12/8
     * 多线程推送酒店房型数据
     */
    class threadPushRoomPriceAndStatusThread implements Callable<Result<Integer>> {
        SwitchHotelUpEntity switchHotelUpEntity;

        public threadPushRoomPriceAndStatusThread(SwitchHotelUpEntity switchHotelUpEntity) {
            this.switchHotelUpEntity = switchHotelUpEntity;
        }
        @Override
        public Result<Integer> call() throws Exception {
            int day=3;

            Map<String, Object> params = new HashMap<>();
            params.put("days", day);
            List<RoomDataEntityVo> roomDataEntityVo = new ArrayList<>();
            List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(switchHotelUpEntity.getHotelId());
            tab:for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                //2.获取美团房价
                params.put("goodsId", switchCreateRoomEntity.getMtGoodId());
                List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
                if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                    log.info("美团的产品价格日历数据为空");
                    continue tab;
                }
                //3.获取美团的房态
                params.put("hotelId", switchCreateRoomEntity.getMtHotelId());
                List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, switchCreateRoomEntity.getMtGoodId());
                if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
                    continue tab;
                }

                //5.封装房型推送数据实体
                List<RoomDataEntityVo> roomDataEntityVos = null;
                try {
                    roomDataEntityVos = roomDataEntityVo(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos, mtHotelGoodsStatusDetailStateVos);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (!ObjectUtils.isEmpty(roomDataEntityVos) && roomDataEntityVos.size() > 0) {
                    roomDataEntityVo.addAll(roomDataEntityVos);
                }
            }
            Integer f=0;
            if(roomDataEntityVo.size()>0){
                List<List<RoomDataEntityVo>> RoomDataEntityVoLists = ListUtils.parititon(roomDataEntityVo, 299);
                BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
                Result<Object> resultq=new Result<>();
                log.info("==============酒店id为{}RoomDataEntityVoLists的长度为{}",switchHotelUpEntity.getHotelId(),roomDataEntityVo.size());
                for (List<RoomDataEntityVo> roomDataEntityVos1 : RoomDataEntityVoLists) {
                    batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos1);
                    batchPushRoomVo.setHotelId(switchHotelUpEntity.getHotelId());
                    log.info("======酒店id为{}请求的json数据为{}",switchHotelUpEntity.getHotelId(), JSON.toJSONString(roomDataEntityVos1));
                    Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                    log.info("=============酒店id为{}请求结果为{}",switchHotelUpEntity.getHotelId(),result.getMsg());
                    resultq.setMsg(result.getMsg());
                    if(result.getCode()==CommonConstants.SUCCESS){
                        f=1;
                    }else if(result.getMsg().toString().contains("数据重复")){
                        f=1;
                    }
                    if (result.getMsg().toString().contains("请求过于频繁")) {
                        try {
                            Thread.sleep(1000);
                            switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }else{
                log.info("==============酒店id为{}RoomDataEntityVoLists的长度为{}",switchHotelUpEntity.getHotelId(),roomDataEntityVo.size());
            }
            if(f==1){
                f=switchHotelUpEntity.getHotelId();
            }
            return new Result<>(f);
        }
    }

    public List<RoomDataEntityVo> roomDataEntityVo(SwitchCreateRoomEntity switchCreateRoomEntity, List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos, List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos) throws InvocationTargetException, IllegalAccessException {
        Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = switchPushRoomService.getOnlinePriceSet();
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //遍历美团价格
        RoomDataEntityVo roomDataEntityVo;
        RoomDataEntityVo qunarRoomDataEntityVo;
        RoomDataEntityVo b2bRoomDataEntityVo;
        Map<String, Object> map;
        double price = 0.0;
        double channelPrice = 0.0;
        SwitchHotelActiveTagEntity switchHotelActiveTagEntity;
        RoomPriceModelVo roomPriceModelVo;
        RoomPriceModelVo qunarroomPriceModelVo;
        RoomPriceModelVo b2broomPriceModelVo;
        RoomPriceModelVo channelroomPriceModelVo;
        RoomStatusModelVo roomStatusModelVo;
        RoomInventoryModelVo roomInventoryModelVo;
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        for (MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo : mtHotelGoodsPriceBaseDetailVos) {
            //携程
            roomDataEntityVo = new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //去哪儿
            qunarRoomDataEntityVo = new RoomDataEntityVo();
            qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //B2B
            b2bRoomDataEntityVo = new RoomDataEntityVo();
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //针对统一的进行价格公式计算
            map = new HashMap<>();
            //判断是否参加促销活动
            switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), mtHotelGoodsPriceBaseDetailVo.getDate());
            if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                map = switchPushRoomService.getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
            } else {
                String currentWeekDay = DateUtil.dayForWeek(mtHotelGoodsPriceBaseDetailVo.getDate());
                //促销
                if (!ObjectUtils.isEmpty(switchHotelActiveTagEntity)&&DateUtil.commpareDay(switchHotelActiveTagEntity.getStartTime(),mtHotelGoodsPriceBaseDetailVo.getDate())&&DateUtil.commpareDay(mtHotelGoodsPriceBaseDetailVo.getDate(),switchHotelActiveTagEntity.getEndTime())) {
                    map = switchPushRoomService.getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), switchHotelActiveTagEntity);
                } else {//判断当前周几，是否符合促销活动
                    map = switchPushRoomService.getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
                }
            }
            //如果价格符合公式，房态可预定 有库存就进行设置推送
            price = Double.parseDouble(map.get("ctripPrice").toString());
            channelPrice = Double.parseDouble(map.get("qunarPrice").toString());
            //房价推送实体
            //携程
            roomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //去哪儿
            qunarRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            qunarRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //b2b
            b2bRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            b2bRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //携程房价实体
            roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setRoomPrice(price);
            roomPriceModelVo.setCurrency("CNY");
            //去哪儿房价实体
            qunarroomPriceModelVo = new RoomPriceModelVo();
            qunarroomPriceModelVo.setRoomPrice(channelPrice);
            qunarroomPriceModelVo.setCurrency("CNY");
            //b2b房价实体
            b2broomPriceModelVo = new RoomPriceModelVo();
            org.apache.commons.beanutils.BeanUtils.copyProperties(b2broomPriceModelVo, qunarroomPriceModelVo);
            //channel房价实体
            channelroomPriceModelVo = new RoomPriceModelVo();
            org.apache.commons.beanutils.BeanUtils.copyProperties(channelroomPriceModelVo, qunarroomPriceModelVo);
            //携程
            roomPriceModelVo.setChannel(channel);
            roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
            //去哪儿
            qunarroomPriceModelVo.setChannel(QunarChannel);
            qunarRoomDataEntityVo.setRoomPriceModel(qunarroomPriceModelVo);
            //b2b
            b2broomPriceModelVo.setChannel(b2bChannel);
            b2bRoomDataEntityVo.setRoomPriceModel(b2broomPriceModelVo);
            if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
                String endTime=DateUtil.getNextDays(15);
                roomStatusModelVo = new RoomStatusModelVo();
                if(DateUtil.commpareDay(mtHotelGoodsPriceBaseDetailVo.getDate(),endTime)){
                    roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                }
                roomStatusModelVo.setChannel(channel);
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                //库存推送实体
                roomInventoryModelVo = new RoomInventoryModelVo();
                //可以取消设置为保留房 不可以取消设置为非保留房
                roomInventoryModelVo.setPreservedQuantity(0);
                roomInventoryModelVo.setUnPreservedQuantity(1);
                roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(channel);
                roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                roomDataEntityVos.add(roomDataEntityVo);
            } else {
                //遍历房态
                for (MtHotelGoodsStatusDetailStateVo mtHotelGoodsStatusDetailStateVo : mtHotelGoodsStatusDetailStateVos) {
                    String endTime=DateUtil.getNextDays(15);
                    //匹配同一天日期
                    if (mtHotelGoodsPriceBaseDetailVo.getDate().equals(mtHotelGoodsStatusDetailStateVo.getDate())) {
                        //房态推送实体
                        roomStatusModelVo = new RoomStatusModelVo();
                        if(DateUtil.commpareDay(mtHotelGoodsStatusDetailStateVo.getDate(),endTime)){
                            if (mtHotelGoodsStatusDetailStateVo.getStatus() == 1) {
                                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                            } else {
                                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                            }
                        }else{
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                        }
                        roomStatusModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                        //房量推送实体
                        roomInventoryModelVo = new RoomInventoryModelVo();
                        //可以取消设置为保留房 不可以取消设置为非保留房
                        roomInventoryModelVo.setPreservedQuantity(0);
                        roomInventoryModelVo.setUnPreservedQuantity(1);
                        roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                        roomInventoryModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                        roomDataEntityVos.add(roomDataEntityVo);
                        roomDataEntityVos.add(qunarRoomDataEntityVo);
                        roomDataEntityVos.add(b2bRoomDataEntityVo);
                    }
                }
            }
        }
        return roomDataEntityVos;
    }

    /**
     * 获取美团产品价格
     */
    public List<MtHotelGoodsPriceBaseDetailVo> getMtGoodsPrice(Map<String, Object> params) {
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = new ArrayList<>();
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_PRICE_BY_HOTEL_ID.getUrl();
        try {
            Result<List<MtHotelGoodsPriceBaseDetailVo>> result1 = switchRestTempaleUtilsService.sendPostRequestGetGoodsPrice(url, params);
            if (result1.getCode() == CommonConstants.SUCCESS) {
                mtHotelGoodsPriceBaseDetailVos = result1.getData();
                if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                    log.info("=============美团的产品价格日历返回数据为空=====================");
                } else {
                    log.info("=============美团的产品价格日历返回数据成功，条数为{}", mtHotelGoodsPriceBaseDetailVos.size());
                }
            }
        } catch (Exception e) {
            log.info("=============获取产品价格日历发生的异常为{}============", e.getMessage());
            return new ArrayList<>();
        }
        return mtHotelGoodsPriceBaseDetailVos;
    }

    /**
     * 获取美团房态
     */
    public List<MtHotelGoodsStatusDetailStateVo> getMtGoodsStatus(Map<String, Object> params, int mtGoodId) {
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_STATUS_BY_DAYS.getUrl();
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = new ArrayList<>();
        try {
            Result<Map<Integer, List<MtHotelGoodsStatusDetailStateVo>>> result2 = switchRestTempaleUtilsService.sendPostRequestGetGoodsStatus(url, params);
            if (result2.getCode() == CommonConstants.SUCCESS) {
                Map<Integer, List<MtHotelGoodsStatusDetailStateVo>> map = result2.getData();
                if (ObjectUtils.isEmpty(map)) {
                    log.info("=============美团的产品房态返回数据为空=====================");
                } else {
                    //产品房态
                    if (map.containsKey(mtGoodId)) {
                        mtHotelGoodsStatusDetailStateVos = map.get(mtGoodId);
                        log.info("==========产品房态===========，条数为{}", mtHotelGoodsStatusDetailStateVos.size());
                    }
                }
            }
        } catch (Exception e) {
            log.info("========获取美团房态发生的异常为{}==================", e.getMessage());
        }
        return mtHotelGoodsStatusDetailStateVos;
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/24
     * 获取酒店列表
     * @param genre
     * 2021-05-24 添加优势酒店set集合 和 普通酒店set
     */
    @Override
    public Result<Object> getUpHotelRpOrFtAsc(Integer genre) {
        if (null != redisService.get("oper_swmt_sub_one_day")) {//美团操作售卖天数减少，当前返回优势普通酒店不进行更新
            List<Integer> list = new ArrayList<>();
            if (genre == 0) {
                Set<Object> set = redisService.getMembers(CommonConstants.SWITCH_SALE_HOTEL_VIP);
                set.forEach(e -> {
                    list.add((Integer) e);
                });
                log.info("===========ft的酒店数据长度为{}=====", list.size());
            } else {
                Set<Object> set = redisService.getMembers(CommonConstants.SWITCH_SALE_HOTEL_NORMAL);
                set.forEach(e -> {
                    list.add((Integer) e);
                });
                log.info("===========rp的酒店数据长度为{}=====", list.size());
            }
            return new Result<>(GsonUtils.GsonString(list), "success");
        }
        Calendar calendar=Calendar.getInstance();
        int minute=calendar.get(Calendar.MINUTE);
        if(minute==10||minute==30||minute==50){
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            executorService.submit(() -> {
                switchVipToNormalCloseStatus();
            });
            executorService.shutdown();
        }
        String controlKey="switch_control_is_share_data";
        List<Integer> list = new ArrayList<>();
        if(minute==30&&!redisService.exists(controlKey)||redisService.exists("switch_first_up_hotel_add_cache")) {
            redisService.set(controlKey,1);
            //先从优势集合 普通集合获取数据
            long time = System.currentTimeMillis();
            //如果不存在就进行初始化，存在也进行更新
            int first = 0;
            if (!redisService.exists(CommonConstants.SWITCH_SALE_HOTEL_VIP)) {
                first = 1;
                initVipAndNormalSet(0);
            }
            if (genre == 0) {
                list = switchHotelLevelMapper.selectHotelByGenre(0);
                log.info("===========ft的酒店数据长度为{}=====", list.size());
            } else {
                list = switchHotelLevelMapper.selectHotelByGenre(1);
                log.info("===========rp的酒店数据长度为{}=====", list.size());
            }
            if (first == 0) {
                initVipAndNormalSet(1);
            }
            long endTime = System.currentTimeMillis();
            log.info("=============获取跑rp和房态酒店接口供花费{}==============",(endTime-time));
            redisService.remove(controlKey);
        }else{
            redisService.set(controlKey,1);
            if (genre == 0) {
                list = switchHotelLevelMapper.selectHotelByGenre(0);
                log.info("===========ft的酒店数据长度为{}=====", list.size());
            } else {
                list = switchHotelLevelMapper.selectHotelByGenre(1);
                log.info("===========rp的酒店数据长度为{}=====", list.size());
            }
            redisService.remove(controlKey);
        }
        return new Result<>(GsonUtils.GsonString(list),"success");
    }

    /**
     * 优势酒店和普通酒店进行初始化
     */
    public void initVipAndNormalSet(int genre){
        List<Integer> list=new LinkedList <>();
        List<Integer> orderList=new ArrayList<>();
        List<Integer> otherList=new ArrayList<>();
        List<Integer> vipList=new ArrayList<>();
        //普通酒店
        double rpRate=6.8;
        String key=CommonConstants.SYSTEM_BASE_SET_TO_MEITUAN_RP_RATE;
        if(redisService.exists(key)){
            rpRate= (double) redisService.get(key);
        }
        //优势酒店比例
        double ftRate=3.2;
        key=CommonConstants.SYSTEM_BASE_SET_TO_MEITUAN_FT_RATE;
        if(redisService.exists(key)){
            ftRate= (double) redisService.get(key);
        }
        int count=0;
        //获取所有上架酒店有产品的酒店数据
        list = switchHotelUpMapper.getUpHotelAsc();
        count=list.size();
        //获取优势酒店数据
        vipList=switchHotelLevelMapper.selectHotelByGenre(0);
        log.info("===========总酒店个数为{}============",count);
        int ftRateNUm=(int) Math.ceil(count/(rpRate+ftRate)*ftRate);
        log.info("===========计算出来需要放入优势酒店个数为{}============",ftRateNUm);
        //普通酒店数量
        int rpRateNum= count-ftRateNUm;
        log.info("===========计算出来普通放入普通酒店个数为{}============",rpRateNum);
        //1.如有新增的酒店,先找出来放入到表里
        //2.如果是第一次的话,就相当于初始化
        List<SwitchCreateRoomEntity> orderHotel=switchHotelLevelMapper.selectNoExists();
        List<SwitchHotelLevelEntity> switchHotelLevelEntities=new ArrayList<>();
        List<SwitchHotelLevelLogEntity> switchHotelLevelLogEntities=new ArrayList<>();
        long startTime=System.currentTimeMillis();
        if(!ObjectUtils.isEmpty(orderHotel)){
            log.info("======有{}家需要放入表里===========",orderHotel.size());
            for(SwitchCreateRoomEntity switchCreateRoomEntity:orderHotel){
                SwitchHotelLevelEntity switchHotelLevelEntity=new SwitchHotelLevelEntity();
                switchHotelLevelEntity.setCreateTime(new Date());
                switchHotelLevelEntity.setGenre(1);
                switchHotelLevelEntity.setMtHotelId(switchCreateRoomEntity.getMtHotelId());
                switchHotelLevelEntity.setHotelId(switchCreateRoomEntity.getHotelId());
                int isOrder=switchOrderInfoMapper.selectCountByHotelId(switchCreateRoomEntity.getHotelId());
                if(isOrder>0){
                    switchHotelLevelEntity.setIsOrder(1);
                }
                switchHotelLevelEntities.add(switchHotelLevelEntity);
                SwitchHotelLevelLogEntity switchHotelLevelLogEntity=new SwitchHotelLevelLogEntity();
                switchHotelLevelLogEntity.setCreateTime(new Date());
                switchHotelLevelLogEntity.setGenre(1);
                switchHotelLevelLogEntity.setMtHotelId(switchCreateRoomEntity.getMtHotelId());
                switchHotelLevelLogEntity.setHotelId(switchCreateRoomEntity.getHotelId());
                switchHotelLevelLogEntity.setUpdateTime(new Date());
                switchHotelLevelLogEntity.setRemark("普通酒店");
                if(isOrder>0){
                    switchHotelLevelLogEntity.setIsOrder(1);
                }
                switchHotelLevelMapper.insert(switchHotelLevelEntity);
                switchHotelLevelLogMapper.insert(switchHotelLevelLogEntity);
            }
            long endTime=System.currentTimeMillis();
            log.info("=========耗费的时间为{}====",(endTime-startTime));
        }
        //目前的优势酒店长度
        int vipSize=vipList.size();
        log.info("=========目前跑优势酒店的个数为{}====",vipSize);
        int lessSize=ftRateNUm-vipSize;
        //如果lessSize小于0 需要从现有的优势酒店移出部分酒店到普通酒店里
        if(lessSize<0){
            log.info("===========需要从优势酒店移动{}家放入普通酒店里==========",Math.abs(lessSize));
            List<SwitchHotelLevelEntity> removeList=switchHotelLevelMapper.selectVipHotelToNormalHotel(Math.abs(lessSize));
            List<Integer> updateList=new ArrayList<>();
            switchHotelLevelLogEntities=new ArrayList<>();
            String keyss="switch_vip_to_normal";
            for(SwitchHotelLevelEntity switchHotelLevelEntity:removeList){
                redisService.add(keyss,switchHotelLevelEntity.getMtHotelId());
                SwitchHotelLevelLogEntity switchHotelLevelLogEntity=new SwitchHotelLevelLogEntity();
                switchHotelLevelLogEntity.setCreateTime(new Date());
                switchHotelLevelLogEntity.setGenre(1);
                switchHotelLevelLogEntity.setMtHotelId(switchHotelLevelEntity.getMtHotelId());
                switchHotelLevelLogEntity.setHotelId(switchHotelLevelEntity.getHotelId());
                switchHotelLevelLogEntity.setIsOrder(switchHotelLevelEntity.getIsOrder());
                switchHotelLevelLogEntity.setUpdateTime(new Date());
                switchHotelLevelLogEntity.setRemark("从优势酒店->普通酒店");
                updateList.add(switchHotelLevelEntity.getHotelId());
                switchHotelLevelLogEntities.add(switchHotelLevelLogEntity);
            }
            int num=switchHotelLevelMapper.updateGenreByHotelId(updateList,1);
            if(num>0){
                switchHotelLevelLogMapper.insertList(switchHotelLevelLogEntities);
            }
        }else{//如果lessSize>0需要从普通酒店里移有订单的酒店放入优势酒店里
            log.info("==========还需要补{}家放入",lessSize);
            if(lessSize>0){
                List<SwitchHotelLevelEntity> removeList=switchHotelLevelMapper.selectNormalHotelToVip(Math.abs(lessSize));
                log.info("==========从普通酒店获取{}家放入========",removeList.size());
                List<Integer> updateList=new ArrayList<>();
                switchHotelLevelLogEntities=new ArrayList<>();
                for(SwitchHotelLevelEntity switchHotelLevelEntity:removeList){
                    SwitchHotelLevelLogEntity switchHotelLevelLogEntity=new SwitchHotelLevelLogEntity();
                    switchHotelLevelLogEntity.setCreateTime(new Date());
                    switchHotelLevelLogEntity.setGenre(0);
                    switchHotelLevelLogEntity.setMtHotelId(switchHotelLevelEntity.getMtHotelId());
                    switchHotelLevelLogEntity.setIsOrder(switchHotelLevelEntity.getIsOrder());
                    switchHotelLevelLogEntity.setUpdateTime(new Date());
                    switchHotelLevelLogEntity.setHotelId(switchHotelLevelEntity.getHotelId());
                    switchHotelLevelLogEntity.setRemark("从普通酒店->优势酒店");
                    updateList.add(switchHotelLevelEntity.getHotelId());
                    switchHotelLevelLogEntities.add(switchHotelLevelLogEntity);
                }
                int num=switchHotelLevelMapper.updateGenreByHotelId(updateList,0);
                if(num>0){
                    switchHotelLevelLogMapper.insertList(switchHotelLevelLogEntities);
                }
            }else{
                log.info("==========优势酒店集合已经满了无需移动数据====================");
            }
        }
        orderList=switchHotelLevelMapper.selectHotelByGenre(0);
        otherList=switchHotelLevelMapper.selectHotelByGenre(1);
        log.info("======优势酒店的数量为{},普通酒店的数量为{},总酒店数量为{}====",orderList.size(),otherList.size(),count);
        //代表第一次
        if(genre==0){
            String keys=CommonConstants.SWITCH_SALE_HOTEL_VIP;
            orderList.forEach(e->{
                redisService.add(keys,e);
            });
            String common_key=CommonConstants.SWITCH_SALE_HOTEL_NORMAL;
            otherList.forEach(e->{
                redisService.add(common_key,e);
            });
        }else{//异步更新
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            executorService.submit(new InitDataThread(orderList,otherList));
            executorService.shutdown();
        }
    }
    //初始化优势酒店集合+普通酒店集合
    class InitDataThread implements Runnable{
        private List<Integer> advantage;
        private List<Integer> ordinary;

        public InitDataThread(List<Integer> advantage, List<Integer> ordinary) {
            this.advantage = advantage;
            this.ordinary = ordinary;
        }

        @Override
        public void run() {
            redisService.remove(CommonConstants.SWITCH_SALE_HOTEL_VIP);
            String key=CommonConstants.SWITCH_SALE_HOTEL_VIP;
            this.advantage.forEach(e->{
                /* log.info("=====酒店ID{}加入优势酒店集合===========",e);*/
                redisService.add(key,e);
            });
            String common_key=CommonConstants.SWITCH_SALE_HOTEL_NORMAL;
            redisService.remove(common_key);
            this.ordinary.forEach(e->{
                /*  log.info("=====酒店ID{}加入普通酒店集合===========",e);*/
                redisService.add(common_key,e);
            });
        }
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/25
     * 效验在售酒店是否有产品待创建
     */
    @Override
    public Result<Object> checkSaleHotelRoomId() {
        String key="switch_sale_hotel_having_room_list";
        Integer hotelId = null;
        if(redisService.exists(key)){
            hotelId= (Integer) redisService.lPop(key);
        }else{
            List<Integer> hotelIds=switchHotelUpMapper.selectSaleHotelListByRoomList();
            hotelIds.forEach(e->{
                redisService.lPush(key,e);
            });
            return  new Result<>();
        }
        log.info("==========hotelIds的长度为{}========",redisService.listSize(key));
        if(redisService.listSize(key)<1){
            redisService.remove(key);
        }
        List<Integer> masterBaiscRoomId=new ArrayList<>();
        //先获取美团的id
        String mtHotelId="";
        Map<String,String> params=new HashMap<>();
        params.put("masterHotelId", String.valueOf(hotelId));
        String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
        Result result;
        try {
            result= switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url,params);
            if(result.getCode()==CommonConstants.SUCCESS){
                mtHotelId=result.getData().toString();
                log.info("==========美团的酒店id为============{}",mtHotelId);
                url = CommonUrlConstants.MEITUAN_HOST+"/"+ MtRequestUrlEnums.GET_MT_GOODS_BY_HOTEL_ID.getUrl();
                Map<String, Integer> param = new HashMap<>();
                param.put("hotelId", Integer.valueOf(mtHotelId));
                Map<String, List<MtHotelGoodsDto>> goodsMap = new HashMap<>();
                try {
                    result = switchRestTempaleUtilsService.sendPostRequest(url, param);
                    if (result.getCode() != CommonConstants.SUCCESS) {
                        log.info("==========获取美团的产品列表数据失败,错误原因是{}=============", result.getMsg());
                        return new Result<>("获取美团的产品列表数据失败", CreateBasicRoomStatusEnums.CATCH.getCode());
                    } else {
                        if (!ObjectUtils.isEmpty(result.getData())) {
                            goodsMap = (Map<String, List<MtHotelGoodsDto>>) result.getData();
                            for(Map.Entry<String,List<MtHotelGoodsDto>> entry:goodsMap.entrySet()){
                                log.info("====================真实的房型id为{}==========",entry.getKey());
                                List<MtHotelGoodsDto> mtHotelGoodsDtos=entry.getValue();
                                boolean isCanCreeate=false;
                                //判断是否有符合创建的产品
                                switchTab:for(MtHotelGoodsDto mtHotelGoodsDto:mtHotelGoodsDtos){
                                    if(mtHotelGoodsDto.getMtGoodsStatus()==3){
                                        continue switchTab;
                                    }
                                    //过滤钟点房
                                    if (mtHotelGoodsDto.getMtGoodsType() ==2) {
                                        continue switchTab;
                                    }
                                    //过滤掉需要身份证验证的
                                    if(mtHotelGoodsDto.getMtNeedIdentityCard()==1){
                                        continue switchTab;
                                    }
                                    /**
                                     * 过滤掉需要连住的产品
                                     * 如果最少入住天数>1 产品暂时不要
                                     * 如果最少预定间数>1 产品暂时不要
                                     */
                                    List<MtHotelGoodsBookRuleDto> mtHotelGoodsBookRuleDtos=mtHotelGoodsDto.getBookRuleList();
                                    if(!ObjectUtil.isEmpty(mtHotelGoodsBookRuleDtos)&&mtHotelGoodsBookRuleDtos.size()>0){
                                        for(MtHotelGoodsBookRuleDto mtHotelGoodsBookRuleDto:mtHotelGoodsBookRuleDtos){
                                            if(mtHotelGoodsBookRuleDto.getMtSerialCheckinMin()>1||mtHotelGoodsBookRuleDto.getMtRoomCountMin()>1){
                                                continue switchTab;
                                            }
                                        }
                                    }
                                    //过滤掉第三方开票方
                                    MtHotelGoodsInvoiceDto mtHotelGoodsInvoiceDto=mtHotelGoodsDto.getInvoice();
                                    if(!ObjectUtils.isEmpty(mtHotelGoodsInvoiceDto)){
                                        if(mtHotelGoodsInvoiceDto.getInvoiceMode()==3||mtHotelGoodsInvoiceDto.getInvoiceMode()==2){
                                            continue switchTab;
                                        }
                                    }
                                    //过滤掉产品名称需要证件的产品
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("护士证")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("户籍")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("资格证")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("学生证")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("证件")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("零点后入住")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("额外")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("另加")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("仅限24:00后住")){
                                        continue switchTab;
                                    }
                                    if(mtHotelGoodsDto.getMtGoodsName().contains("入住")&&mtHotelGoodsDto.getMtGoodsName().contains("小时")){
                                        continue switchTab;
                                    }
                                    //如果美團的產品id+酒店id有對應的映射過濾
                                    SwitchCreateRoomEntity switchCreateRoomByMt = switchCreateRoomMapper.selectByMtGoodsIdAndHotelId(Integer.valueOf(mtHotelGoodsDto.getMtHotelId()), Integer.valueOf(mtHotelGoodsDto.getMtGoodsId()));
                                    if(ObjectUtils.isEmpty(switchCreateRoomByMt)){
                                        isCanCreeate=true;
                                    }
                                }
                                if(isCanCreeate){
                                    url =CommonUrlConstants.COMPARE_HOST+ CompareRequestUrlEnums.GET_HOTEL_BASIC_ROOM_INFO_BY_MT_HOTEL_ID_AND_MT_ROOM_ID.getUrl();
                                    param.put("mtHotelId", Integer.valueOf(mtHotelId));
                                    param.put("mtRoomId",Integer.valueOf(entry.getKey()));
                                    Result<CompareHotelBasicRoom> result1 = switchRestTempaleUtilsService.sendPostRequestByGetSwitchHotelIdAndRoomId(url, param);
                                    CompareHotelBasicRoom compareHotelBasicRoom=result1.getData();
                                    if(!ObjectUtils.isEmpty(compareHotelBasicRoom)){
                                        log.info("===========有映射关系修改创建数据==============");
                                        //更新创建物理房型表状态
                                        masterBaiscRoomId.add(Integer.valueOf(compareHotelBasicRoom.getSwitchHotelRoomId()));
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    log.info("===============获取美团的产品列表数据，产生的异常为{}=======", e.getMessage());
                    return new Result<>("获取美团的产品列表数据失败", CreateBasicRoomStatusEnums.CATCH.getCode());
                }
            }
        }catch (Exception e){
            log.info("=======获取美团酒店id出现异常==============");
        }
        if(!ObjectUtils.isEmpty(masterBaiscRoomId)&&masterBaiscRoomId.size()>0){
            switchCreateBasicRoomMapper.updateBatchCreateState(StringUtils.join(masterBaiscRoomId,","));
        }
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/31
     * 获取没有订单酒店的数据并且设置为停售
     */
    @Override
    public Result<Object> bookTimeCloseNoOrderHotelList() {
        List<Integer> hotelIds=switchHotelUpMapper.getNoOrderHotelList();
        //0点异步通道价格关闭,50分钟
        redisService.setUnit(CallbackConstants.CLOSE_MT_CB_PRICE,1,50L,TimeUnit.MINUTES);
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }else{
            new BookTimeHotelDownThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }

    class BookTimeHotelDownThread implements Runnable{
        private  List<Integer> hotelIds;

        public BookTimeHotelDownThread(List<Integer> list) {
            this.hotelIds = list;
        }

        @Override
        public void run() {
            List<List<Integer>> lists=ListUtils.parititon(this.hotelIds,50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
            for(List<Integer> list:lists){
                //设置停售
                Integer[] hotelList = new Integer[list.size()];
                Result<Object> result = pushHotelStatus(list.toArray(hotelList), 0);
                if((result.getCode()==CommonConstants.SUCCESS)||(result.getMsg().toString().contains("MIPHotel"))){
                    //更新上架表的状态
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),4);
                    //添加操作日志
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                    switchHotelUpLogEntities=new ArrayList<>();
                    for(Integer hotelId:list){
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(4);
                        switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点停售");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                    log.info("=========关闭售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                }else {
                    try {
                        Thread.sleep(10000);
                        result = pushHotelStatus(list.toArray(hotelList), 0);
                        if(result.getCode()==CommonConstants.SUCCESS){
                            //更新上架表的状态
                            switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),4);
                            //添加操作日志
                            SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                            switchHotelUpLogEntities=new ArrayList<>();
                            for(Integer hotelId:list){
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(hotelId);
                                switchHotelUpLogEntity.setUp(4);
                                switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点停售");
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                            }
                            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                            log.info("=========关闭售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //刪除緩存
            //删除酒店缓存
            if(redisService.exists("goods_query_job_up_hotel_data")){
                redisService.remove("goods_query_job_up_hotel_data");
            }
            //删除房态队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus");
            }
            //删除价格队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlprice")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlprice");
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/31
     * 开启暂时关闭的酒店数据列表
     */
    @Override
    public Result<Object> bookTimeStartNoOrderHotelList() {
        List<Integer> hotelIds=switchHotelUpMapper.getBookTimeDownHotelList();
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>();
        }else{
            new BookTimeHotelUpThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }
    class BookTimeHotelUpThread implements Runnable{
        private List<Integer> hotelIds;

        public BookTimeHotelUpThread(List<Integer> hotelIds) {
            this.hotelIds = hotelIds;
        }
        @Override
        public void run() {
            List<List<Integer>> lists=ListUtils.parititon(this.hotelIds,50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
            for(List<Integer> list:lists){
                //设置停售
                Integer[] hotelList = new Integer[list.size()];
                Result<Object> result = pushHotelStatus(list.toArray(hotelList), 1);
                if(result.getCode()==CommonConstants.SUCCESS){
                    //更新上架表的状态
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),3);
                    //添加操作日志
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                    switchHotelUpLogEntities=new ArrayList<>();
                    for(Integer hotelId:list){
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(3);
                        switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点开售");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                        switchHotelUpEntity.setHotelId(hotelId);
                        ExecutorService executorService = Executors.newFixedThreadPool(1);
                        executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                        executorService.shutdown();
                        try {
                            Thread.sleep(300);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                    log.info("=========开启售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                }else{
                    try {
                        Thread.sleep(10000);
                        result = pushHotelStatus(list.toArray(hotelList), 1);
                        if(result.getCode()==CommonConstants.SUCCESS){
                            //更新上架表的状态
                            switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),3);
                            //添加操作日志
                            SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                            switchHotelUpLogEntities=new ArrayList<>();
                            for(Integer hotelId:list){
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(hotelId);
                                switchHotelUpLogEntity.setUp(3);
                                switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点开售");
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                                SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                                switchHotelUpEntity.setHotelId(hotelId);
                                ExecutorService executorService = Executors.newFixedThreadPool(1);
                                executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                                executorService.shutdown();
                                try {
                                    Thread.sleep(300);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                            log.info("=========开启售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //删除酒店缓存
            if(redisService.exists("goods_query_job_up_hotel_data")){
                redisService.remove("goods_query_job_up_hotel_data");
            }
            //删除房态队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus");
            }
            //删除价格队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlprice")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlprice");
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 替换没有订单的酒店 3000家
     */
    @Override
    public Result<Object> replaceNoOrderHotel() {
        //定义下架酒店的数量
        String key="switch_hotel_up_hotel_list_num";
        int num=1000;
        if(redisService.exists(key)){
            num= (int) redisService.get(key);
        }
        List<Integer> hotelIds=switchHotelUpMapper.selectNoOrderHotelListByWeek(num);
        log.info("============酒店长度为{}=====",hotelIds.size());
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>();
        }else{
            new ReplaceHotelThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }

    class ReplaceHotelThread implements Runnable{
        private List<Integer> hotelIds;
        public ReplaceHotelThread(List<Integer> hotelIds) {
            this.hotelIds = hotelIds;
        }
        @Override
        public void run() {
            List<List<Integer>> lists=ListUtils.parititon(this.hotelIds,50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
            for(List<Integer> list:lists){
                //设置停售
                Integer[] hotelList = new Integer[list.size()];
                Result<Object> result = pushHotelStatus(list.toArray(hotelList), 0);
                if((result.getCode()==CommonConstants.SUCCESS)||(result.getMsg().toString().contains("MIPHotel"))){
                    //更新上架表的状态,记录下线
                    switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","),4);
                    //添加操作日志
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                    switchHotelUpLogEntities=new ArrayList<>();
                    for(Integer hotelId:list){
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(4);
                        switchHotelUpLogEntity.setUsername("admin-无订单酒店下线");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                        switchHotelUpEntity.setHotelId(hotelId);
                    }
                    switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                    log.info("=========开始下架售卖无订单酒店为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                }else {
                    try {
                        Thread.sleep(8000);
                        result = pushHotelStatus(list.toArray(hotelList), 0);
                        if(result.getCode()==CommonConstants.SUCCESS){
                            //更新上架表的状态
                            switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","),4);
                            //添加操作日志
                            SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                            switchHotelUpLogEntities=new ArrayList<>();
                            for(Integer hotelId:list){
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(hotelId);
                                switchHotelUpLogEntity.setUp(4);
                                switchHotelUpLogEntity.setUsername("admin-无订单酒店下线");
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                                SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                                switchHotelUpEntity.setHotelId(hotelId);
                                removeOrAddHotelRelationCache(hotelId,0);
                            }
                            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                            log.info("=========开始下架售卖无订单酒店为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //删除酒店缓存
            if(redisService.exists("goods_query_job_up_hotel_data")){
                redisService.remove("goods_query_job_up_hotel_data");
            }
            //删除房态队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus");
            }
            //删除价格队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlprice")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlprice");
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 重新上架新的酒店
     */
    @Override
    public Result<Object> againNewHotel() {
        //定义下架酒店的数量
        String key="switch_hotel_up_hotel_list_num";
        int num=1000;
        if(redisService.exists(key)){
            num= (int) redisService.get(key);
        }
        List<Integer> hotelIds=switchHotelUpMapper.selectHotelByUp(num);
        log.info("============酒店长度为{}=====",hotelIds.size());
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>();
        }else{
            new addHotelThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }


    class addHotelThread implements Runnable{
        private List<Integer> hotelIds;

        public addHotelThread(List<Integer> hotelIds) {
            this.hotelIds = hotelIds;
        }

        @Override
        public void run() {
            List<Integer> common=new ArrayList<>();
            //效验黑名单和产品
            for(Integer hotelId:this.hotelIds){
                //先获取美团的id
                //效验是否黑名单酒店
                //调用美团接口检查是否有被拉入黑名单的酒店
                Integer mtHotelId=switchCreateRoomMapper.selectMtHotelIdByHotelId(hotelId);
                if(ObjectUtils.isEmpty(mtHotelId)){
                    continue;
                }
                Integer[] hotelIds = new Integer[1];
                hotelIds[0] = mtHotelId;
                String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_HOTEL_FAILURE.getUrl();
                Map<String, Object> params = new HashMap<>();
                params.put("hotelIds", hotelIds);
                Result<List<MtHotelDownVo>> result2 = switchRestTempaleUtilsService.sendReuestToMtCheckHotelFailure(url, params);
                List<MtHotelDownVo> mtHotelDownVos = result2.getData();
                if (mtHotelDownVos.size() < 1) {
                    checkHotelGoodStatus(hotelId);
                    common.add(hotelId);
                } else {
                    for (MtHotelDownVo mtHotelDownVo : mtHotelDownVos) {
                        //0 下线  1 上线
                        if (mtHotelDownVo.getStatus() == 1) {
                            //效验是否含有失效产品
                            checkHotelGoodStatus(hotelId);
                            common.add(hotelId);
                        }
                    }
                }
            }
            log.info("=========可以开启售卖的酒店数量为{}===========",common.size());
            List<List<Integer>> lists=ListUtils.parititon(common,50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
            for(List<Integer> list:lists){
                //设置停售
                Integer[] hotelList = new Integer[list.size()];
                Result<Object> result = pushHotelStatus(list.toArray(hotelList), 1);
                if(result.getCode()==CommonConstants.SUCCESS){
                    //更新上架表的状态,记录下线
                    switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","),3);
                    //添加操作日志
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                    switchHotelUpLogEntities=new ArrayList<>();
                    for(Integer hotelId:list){
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(3);
                        switchHotelUpLogEntity.setUsername("admin-新酒店售卖");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                        switchHotelUpEntity.setHotelId(hotelId);
                    }
                    switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                    log.info("=========开始开新酒店售卖为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                }else {
                    try {
                        Thread.sleep(8000);
                        result = pushHotelStatus(list.toArray(hotelList), 1);
                        if((result.getCode()==CommonConstants.SUCCESS)||(result.getMsg().toString().contains("MIPHotel"))){
                            //更新上架表的状态
                            switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","),3);
                            //添加操作日志
                            SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                            switchHotelUpLogEntities=new ArrayList<>();
                            for(Integer hotelId:list){
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(hotelId);
                                switchHotelUpLogEntity.setUp(3);
                                switchHotelUpLogEntity.setUsername("admin-新酒店售卖");
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                                SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                                switchHotelUpEntity.setHotelId(hotelId);
                                removeOrAddHotelRelationCache(hotelId,1);
                            }
                            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                            log.info("=========开始开新酒店售卖为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //删除酒店缓存
            if(redisService.exists("goods_query_job_up_hotel_data")){
                redisService.remove("goods_query_job_up_hotel_data");
            }
            //删除房态队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus");
            }
            //删除价格队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlprice")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlprice");
            }
        }
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 增量上新酒店
     */
    @Override
    public Result<Object> addHotelList() {
        //定义下架酒店的数量
        String key="switch_hotel_up_hotel_list_add_num";
        int num=1000;
        if(redisService.exists(key)){
            num= (int) redisService.get(key);
        }
        List<Integer> hotelIds=switchHotelUpMapper.selectHotelByUp(num);
        log.info("============酒店长度为{}=====",hotelIds.size());
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>();
        }else{
            new addHotelThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }


    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 清除缓存
     */
    public void removeOrAddHotelRelationCache(Integer hotelId,int genre){
        List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(hotelId);
        for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
            if(genre==0){//清除缓存
                //删除早餐缓存
                if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")) {
                    String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_0";
                    if (redisService.exists(key)) {
                        redisService.remove(key);
                    }
                } else if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("640292")) {
                    String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                    if (redisService.exists(key)) {
                        redisService.remove(key);
                    }
                } else {
                    String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                    if (redisService.exists(key)) {
                        redisService.remove(key);
                    }
                }
                //删除酒店id+产品id
                String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if(redisService.exists(key)){
                    redisService.remove(key);
                }
                //删除产品和携程映射关系
                key=CommonConstants.SWITCH_SELLING_REDIS_BY_MT+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId();
                if(redisService.exists(key)){
                    redisService.remove(key);
                }
                //删除取消规则
                key=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_1";
                if(redisService.exists(key)){
                    redisService.remove(key);
                }
                key=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_0";
                if(redisService.exists(key)){
                    redisService.remove(key);
                }
            }else{
                //添加早餐缓存
                if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")) {
                    String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_0";
                    redisService.set(key,1);
                } else if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("640292")) {
                    String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                    redisService.set(key,2);
                } else {
                    String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                    redisService.set(key,switchCreateRoomEntity.getMealCount());
                }
                //酒店id+产品id
                String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                redisService.set(key,switchCreateRoomEntity.getMtRoomId());
                //产品和携程映射关系
                key=CommonConstants.SWITCH_SELLING_REDIS_BY_MT+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId();
                if(redisService.exists(key)){
                    redisService.remove(key);
                }
                //取消规则
                key=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_0";
                redisService.set(key,"0");
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/1/12
     * 获取售卖的酒店判断是否参与售卖
     */
    @Override
    public Result<Object> activeHotelDownAndUp() {
        List<SwitchHotelUpEntity> switchHotelUpEntities=switchHotelUpMapper.selectSaleHotel();
        log.info("============switchHotelUpEntities的长度为{}===",switchHotelUpEntities.size());
        Map<String,String> param=null;
        List<List<SwitchHotelUpEntity>> lists=ListUtils.parititon(switchHotelUpEntities,10);
        List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
        for(List<SwitchHotelUpEntity> list:lists){
            switchHotelUpLogEntities=new ArrayList<>();
            param=new HashMap<>();
            for(SwitchHotelUpEntity switchHotelUpEntity:list){
                //先获取美团的id
                Map<String,String> params=new HashMap<>();
                params.put("masterHotelId", String.valueOf(switchHotelUpEntity.getMasterHotelId()));
                String mtHotelId;
                String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
                Result result;
                try {
                    result= switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url,params);
                    if(result.getCode()==CommonConstants.SUCCESS){
                        mtHotelId=result.getData().toString();
                        param.put(String.valueOf(switchHotelUpEntity.getHotelId()),mtHotelId);
                    }
                }catch (Exception e){
                    log.info("=======获取美团酒店id出现异常==============");
                }
            }
            /*param.put("66990619","495191");*/
            String url= CommonUrlConstants.MEITUAN_HOST+"/"+ MtRequestUrlEnums.GET_MT_HOTEL_ACTIVE_BY_SWITCH_HOTEL_ID.getUrl();
            Result result=switchRestTempaleUtilsService.sendPostRequestToMeiTuanIsAciive(url,param);
            JSONObject jsonObject= JSON.parseObject(JSON.toJSONString(result));
            List<Integer> hotelIds=JacksonUtil.jsonToList(jsonObject.getString("data"),Integer.class);
            log.info("==========hotelIds的长度为{}数据为{}",hotelIds.size(), JSON.toJSONString(hotelIds));
            //对没有活动的酒店进行下线
            if(!ObjectUtils.isEmpty(hotelIds)&&hotelIds.size()>0){
                Integer[] data=new Integer[hotelIds.size()];
                //调用下线接口，并做记录
                Result<Object> result1 = pushHotelStatus(hotelIds.toArray(data), 0);
                log.info("==========美团酒店没有活动进行下线===============");
                if ((result1.getCode()==CommonConstants.SUCCESS)||(result1.getMsg().toString().contains("MIPHotel"))) {
                    SwitchHotelUpLogEntity switchHotelUpLogEntity;
                    for (Integer id : hotelIds) {
                        param.remove(id.toString());
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(id);
                        switchHotelUpLogEntity.setUp(5);
                        switchHotelUpLogEntity.setUsername("没有活动的酒店暂时下线");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    //更新上架表的状态,记录下线
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(hotelIds, ","),5);
                }else if(result1.getMsg().toString().contains("频率")||result1.getMsg().toString().contains("认证失败")){
                    try {
                        Thread.sleep(6000);
                        result1=pushHotelStatus(list.toArray(data), 0);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : hotelIds) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(5);
                            switchHotelUpLogEntity.setUsername("没有活动的酒店暂时下线");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                        //更新上架表的状态,记录下线
                        switchHotelUpMapper.updateHotelStatis(StringUtils.join(hotelIds, ","),5);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            List<Integer> blackHotelId=new ArrayList<>();
            //遍历有活动的酒店
            for(String hotelId:param.keySet()){
                SwitchHotelUpEntity switchHotelUpEntity=switchHotelUpMapper.selectByHotelId(Integer.parseInt(hotelId));
                //说明现在有活动了重新上线
                if(switchHotelUpEntity.getUp()==5){
                    blackHotelId.add(Integer.valueOf(hotelId));
                }
            }
            if(!ObjectUtils.isEmpty(blackHotelId)&&blackHotelId.size()>0){
                Integer[] data=new Integer[blackHotelId.size()];
                //调用上线线接口，并做记录
                Result<Object> result1 = pushHotelStatus(blackHotelId.toArray(data), 1);
                log.info("==========美团酒店有活动进行上线===============");
                if ((result.getCode()==CommonConstants.SUCCESS)||(result.getMsg().toString().contains("MIPHotel"))) {
                    SwitchHotelUpLogEntity switchHotelUpLogEntity;
                    for (Integer id : blackHotelId) {
                        param.remove(id.toString());
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(id);
                        switchHotelUpLogEntity.setUp(3);
                        switchHotelUpLogEntity.setUsername("没有活动的酒店重新上线售卖");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    //更新上架表的状态,记录下线
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(blackHotelId, ","),3);
                }else if(result1.getMsg().toString().contains("频率")||result1.getMsg().toString().contains("认证失败")){
                    try {
                        Thread.sleep(6000);
                        result1=pushHotelStatus(blackHotelId.toArray(data), 1);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : hotelIds) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(3);
                            switchHotelUpLogEntity.setUsername("没有活动的酒店重新上线售卖");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                        //更新上架表的状态,记录下线
                        switchHotelUpMapper.updateHotelStatis(StringUtils.join(blackHotelId, ","),3);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            if(!ObjectUtils.isEmpty(switchHotelUpLogEntities)&&switchHotelUpLogEntities.size()>0){
                switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
            }
            log.info("=============调用结果返回的数据为{}========", JSON.toJSONString(result));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/1/15
     * 获取在售酒店列表进行房型数据更新
     */
    @Override
    public Result<Object> saleHotelUpdateRoomInfo() {
        //获取酒店的取消规则
        getSaleHotelRoomCanceleRule();
        long nowTime=System.currentTimeMillis();
        String keys=CommonConstants.SWITCH_SALE_HOTEL_DATA_LIST;
        SwitchHotelUpEntity switchHotelUpEntity=null;
        log.info("=============现有的酒店长度{}================",redisService.listSize(CommonConstants.SWITCH_SALE_HOTEL_DATA_LIST));
        if(redisService.exists(keys)&&redisService.listSize(CommonConstants.SWITCH_SALE_HOTEL_DATA_LIST)>0){
            String jsonData= (String) redisService.lPop(CommonConstants.SWITCH_SALE_HOTEL_DATA_LIST);
            if (StringUtils.isEmpty(jsonData)) {
                return new Result<>();
            }
            switchHotelUpEntity=JacksonUtil.parse(jsonData,SwitchHotelUpEntity.class);
        }else{
            //如果上一个程序已经进行封装数据了,过滤重复封装
            if(redisService.exists("switch_hotel_uodate_room_info")){
                return new Result<>();
            }
            redisService.set("switch_hotel_uodate_room_info",1);
            List<SwitchHotelUpEntity> switchHotelUpEntities=switchHotelUpMapper.selectSaleHotel();
            if(ObjectUtils.isEmpty(switchHotelUpEntities)||switchHotelUpEntities.size()<1){
                return new Result<>();
            }
            switchHotelUpEntity=switchHotelUpEntities.stream().findFirst().get();
            //异步把数据放入队列
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            executorService.submit(() -> {
                switchHotelUpEntities.forEach(e->{
                    redisService.lPush(CommonConstants.SWITCH_SALE_HOTEL_DATA_LIST,JacksonUtil.objectToJson(e));
                });
                redisService.remove("switch_hotel_uodate_room_info");
            });
            executorService.shutdown();
        }
        if(redisService.exists("switch_hotel_room_update_is_hav_good")){
            return new Result<>();
        }
        redisService.set("switch_hotel_room_update_is_hav_good",1);
        String mtHotelId="";
        //先获取美团的id
        Map<String,String> params=new HashMap<>();
        params.put("masterHotelId", String.valueOf(switchHotelUpEntity.getMasterHotelId()));
        String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
        Result<Object> result;
        try {
            result= switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url,params);
            if(result.getCode()==CommonConstants.SUCCESS){
                mtHotelId=result.getData().toString();
            }
            if(StringUtils.isBlank(mtHotelId)){
                return new Result<>();
            }
            //拉取最新的物理房型信息
            result=switchBasicRoomTypeService.getHotelBasicRoomList(switchHotelUpEntity.getHotelId());
            if(result.getCode()==CommonConstants.SUCCESS){
                //调用美团接口进行房型匹配
                url=CommonUrlConstants.COMPARE_HOST+CompareRequestUrlEnums.COMPARE_HOTEL_ROOM_BY_HOTEL_ID_SQL.getUrl();
                Map<String,Integer> param=new HashMap<>();
                param.put("mtHotelId",Integer.valueOf(mtHotelId));
                param.put("line",2);
                switchRestTempaleUtilsService.sendPostRequestToCompareToCompareHotelRoomId(url,param);
            }
            long endTime=System.currentTimeMillis();
            log.info("========效验在售酒店的房型数据耗时{}=======",(endTime-nowTime));
        }catch (Exception e){
            e.printStackTrace();
        }
        redisService.remove("switch_hotel_room_update_is_hav_good");
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/1/26
     * 导入酒店到黑名单
     */
    @Override
    public Result<Object> sumbitUploadBlack(MultipartFile excelFile) {
        log.info("==============检查黑名单酒店数据开始===============");
        List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=new ArrayList<>();
        List<Integer> blackList=new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            tab:
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(0);
                Double hotelId = cell.getNumericCellValue();
                cell = sheetRow.getCell(1);
                String hotelName=cell.getStringCellValue();
                SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectByHotelId(hotelId.intValue());
                if (!ObjectUtil.isEmpty(switchHotelUpEntity)&&switchHotelUpEntity.getStatus()==2) {
                    log.info("===========hotelName{}已经存在我们系统黑名单了=======",hotelName);
                    continue tab;
                }else{
                    blackList.add(hotelId.intValue());
                }

            }
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        if (blackList.size() > 0) {
            List<List<Integer>> blackHotelIds = ListUtils.parititon(blackList, 50);
            log.info("===============blackHotelIds的数据为{}===", JSON.toJSONString(blackHotelIds));
            for (List<Integer> list : blackHotelIds) {
                Integer[] hotelId = new Integer[list.size()];
                Map<String, Object> updateChannelVoMap = new HashMap<>();
                updateChannelVoMap.put("hotelIDs", list.toArray(hotelId));
                updateChannelVoMap.put("cBookable", 0);
                updateChannelVoMap.put("qBookable", 0);
                updateChannelVoMap.put("channelABookable", 0);
                updateChannelVoMap.put("b2bBookable", 0);
                Result<Object> result=switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                if(result.getMsg().toString().contains("执行频率过快")){
                    try {
                        Thread.sleep(2000);
                        switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","), 2);
                SwitchHotelUpLogEntity switchHotelUpLogEntity;
                for (Integer id : list) {
                    switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                    switchHotelUpLogEntity.setCreateTime(new Date());
                    switchHotelUpLogEntity.setGenre(1);
                    switchHotelUpLogEntity.setHotelId(id);
                    switchHotelUpLogEntity.setUp(2);
                    switchHotelUpLogEntity.setUsername("admin-检查黑名单-记录黑名单");
                    switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,id);
                }
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        if(switchHotelUpLogEntities.size()>0){
            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
        }

        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/3/23
     * 设置酒店是否更新价格和房态的酒店列表
     */
    @Override
    public Result<Object> setCheckSaleHotelPriceAndStatusIsChangeHotelList() {
        //获取上架的酒店列表
        String key=CommonConstants.SWITCH_SALE_HOTEL_CHECK_PRICE_AND_STATUS_IS_CHANGE;
        if(redisService.exists(key)&&redisService.listSize(key)>0){
            return new Result<>();
        }
        if(redisService.exists("switch_have_init_hotel_data_to_cache")){
            return new Result<>();
        }
        redisService.set("switch_have_init_hotel_data_to_cache",1);
        List<Integer> hotelList=switchHotelUpMapper.getSaleHotelListToCheckPriceAndStatus();
        if(!ObjectUtils.isEmpty(hotelList)&&hotelList.size()>0){
            hotelList.forEach(e->{
                redisService.lPush(key,e);
            });
        }
        redisService.remove("switch_have_init_hotel_data_to_cache");
        return new Result<>();
    }


    /***
     * @Author: lmf
     * @Date: 2021/1/27
     * 效验售卖房型的价格房态是否变更
     */
    public Result<Object> checkSaleHotelPriceAndStatusIsChange() {
        //获取上架的酒店列表
        String key=CommonConstants.SWITCH_SALE_HOTEL_CHECK_PRICE_AND_STATUS_IS_CHANGE;
        String num_key="switch_check_hotel_price_and_status_Thread_num";
        int num=20;
        if(redisService.exists(num_key)){
            num= (int) redisService.get(num_key);
        }
        String controlKey="switch_controlr_sale_hotel_price";
        if(redisService.exists(controlKey)){
            return new Result<>();
        }
        redisService.set(controlKey,1);
        String switch_create_room_key="switchCreateRoomKey";
        ExecutorService executorService = Executors.newFixedThreadPool(num);
        for(int i=0;i<num;i++){
            Integer hotelId= (Integer) redisService.lPop(key);
            if(ObjectUtils.isEmpty(hotelId)){
                break;
            }
            String switchCreateRoomKey=switch_create_room_key+hotelId;
            List<SwitchCreateRoomEntity> switchCreateRoomEntities;
            if(!redisService.exists(switchCreateRoomKey)){
                switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(hotelId);
                Random r = new Random(1);
                redisService.set(switchCreateRoomKey,JacksonUtil.objectToJson(switchCreateRoomEntities), (long) r.nextInt(1000));
            }else{
                String str= (String) redisService.get(switchCreateRoomKey);
                switchCreateRoomEntities=JacksonUtil.jsonToList(str,SwitchCreateRoomEntity.class);
            }
            executorService.submit(new switchPriceAndStatusThread(switchCreateRoomEntities,hotelId));
        }
        executorService.shutdown();
        redisService.remove(controlKey);
        return new Result<>();
    }

    class switchPriceAndStatusThread implements Runnable{
        List<SwitchCreateRoomEntity> switchCreateRoomEntities;
        Integer hotelId;
        public switchPriceAndStatusThread(List<SwitchCreateRoomEntity> switchCreateRoomEntities, Integer hotelId) {
            this.switchCreateRoomEntities = switchCreateRoomEntities;
            this.hotelId = hotelId;
        }
        @Override
        public void run() {
            String now=DateUtil.formatDate(DateUtil.getNextDays(-1),"yyyyMMdd");
            String keys="switch_check_price_and_price_"+now;
            if(redisService.exists(keys)){
                redisService.remove(keys);
            }
            keys="switch_check_price_and_price_"+DateUtil.formatDate(DateUtil.getNextDays(0),"yyyyMMdd");
            int num=0;
            if(redisService.exists(keys)){
                num=(int)redisService.get(keys);
            }
            int[] roomIds=new int[this.switchCreateRoomEntities.size()];
            int i=0;
            for(SwitchCreateRoomEntity switchCreateRoomEntity:this.switchCreateRoomEntities){
                roomIds[i++]=switchCreateRoomEntity.getRoomId();
            }
            GetRoomPriceVo getRoomPriceVo=new GetRoomPriceVo();
            getRoomPriceVo.setChannel("Ctrip");
            getRoomPriceVo.setGetPurchasePrice(false);
            getRoomPriceVo.setHotelId(hotelId);
            getRoomPriceVo.setRoomIds(roomIds);
            int day=3;
            if(redisService.isMember(CommonConstants.SWITCH_SALE_HOTEL_VIP,switchCreateRoomEntities.get(0).getMtHotelId())){
                day=getDaysCommonBaseSetForVip();
            }else{
                day=getDaysCommonBaseSetForNormal();
            }
            //凌晨0点-5点 不载入新一天
            Calendar calendar=Calendar.getInstance();
            int hour=calendar.get(Calendar.HOUR_OF_DAY);
            if(hour<=5){
                day=day-1;
            }
            String endTime=DateUtil.getNextDays(day-1);
            getRoomPriceVo.setStartDate(DateUtil.getToday());
            getRoomPriceVo.setEndDate(endTime);
            Result<GetRoonPriceReturnVo> result=switchRoomPriceService.getRoomPriceDirect(getRoomPriceVo);
            GetRoonPriceReturnVo getRoonPriceReturnVo=result.getData();
            Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = switchPushRoomService.getOnlinePriceSet();
            Integer addPrice=0;
            Double addRate=1.0;
            //是否开启获取酒店有独立的价格公式
            if(redisService.exists(CommonConstants.SWITCH_IS_OPEN_HOTEL_OWNER_PRICE_FORMULA)){
                //获取酒店是否有自已独立的价格公式
                priceSetMap=getOnlinePriceSetByData(hotelId,priceSetMap);
            }
            Integer rate= (Integer) redisService.hmGet(CommonConstants.SWITCH_ADJUST_HOTEL_RATE_BY_OUT_PUT_IS_ZERO,hotelId);
            if(!ObjectUtils.isEmpty(rate)){
                priceSetMap.entrySet().forEach(e->{
                    List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities= e.getValue();
                    for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                        //最低只能到10
                        if(switchPriceBaseSetEntity.getRate().doubleValue()>10){
                            switchPriceBaseSetEntity.setRate(BigDecimal.valueOf(switchPriceBaseSetEntity.getRate().doubleValue()-rate.doubleValue()));
                        }
                    }
                    e.setValue(switchPriceBaseSetEntities);
                });
            }
            List<SwitchHotelRoomPriceAndStatusLogEntity> switchHotelRoomPriceAndStatusLogEntities=new ArrayList<>();
            //如果价格返回的数据
            if(!ObjectUtils.isEmpty(getRoonPriceReturnVo.getChannelRoomPrices())&&getRoonPriceReturnVo.getChannelRoomPrices().size()>0){
                //携程
                RoomDataEntityVo roomDataEntityVo = null;
                //去哪儿
                RoomDataEntityVo qunarRoomDataEntityVo=null;
                //b2b
                RoomDataEntityVo b2bRoomDataEntityVo=null;
                //channelA
                RoomDataEntityVo channelRoomDataEntityVo=null;
                //携程价格实体
                RoomPriceModelVo roomPriceModelVo=null;
                //去哪儿价格实体
                RoomPriceModelVo qunarRoomPriceModelVo = null;
                //b2b价格实体
                RoomPriceModelVo b2bRoomPriceModelVo =null;
                for(ChannelRoomPricesVo roomPricesVo:getRoonPriceReturnVo.getChannelRoomPrices()){
                    BatchPushRoomVo batchPushRoomVo=new BatchPushRoomVo();
                    batchPushRoomVo.setHotelId(hotelId);
                    List<RoomDataEntityVo> roomDataEntitys=new ArrayList<>();
                    for(RoomPricesVo pricesVo:roomPricesVo.getRoomPrices()){
                        String time=DateUtil.switchDateParse(pricesVo.getEffectDate());
                        Map<String, Object> priceMap = new HashMap<>();
                        String switch_create_room_single_key="switch_create_room_single_key"+hotelId+"_"+pricesVo.getRoomId();
                        SwitchCreateRoomEntity switchCreateRoomEntity;
                        if(redisService.exists(switch_create_room_single_key)){
                            String json= (String) redisService.get(switch_create_room_single_key);
                            switchCreateRoomEntity=JacksonUtil.parse(json,SwitchCreateRoomEntity.class);
                        }else{
                            switchCreateRoomEntity=switchCreateRoomMapper.selectByHotelIdAndRoomId(hotelId,pricesVo.getRoomId());
                            Random r = new Random(1);
                            redisService.set(switch_create_room_single_key,JacksonUtil.objectToJson(switchCreateRoomEntity),(long)r.nextInt(10000));
                        }
                        //获取价格缓存数据
                        String key=CallbackConstants.REDIS_KEY_CALLBACK_SUB_PRICE_HEAD+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_"+time;
                        String key2=CallbackConstants.REDIS_KEY_CALLBACK_CHANGE_PRICE_HEAD+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_"+time;
                        if(!redisService.exists(key)){
                          //  SendUtils.dingMsgNotLog("二线"+time+"缓存没有数据,房型ID为"+pricesVo.getRoomId(),"暂未价格信息",MessageEnums.genre.SWITCH_HOTEL_STATUS_AND_PRICE_NOTITY.getCode(),restTemplate);
                            log.info("=====美团的酒店id{}美团的产品id{}日期为{}无价格数据====",switchCreateRoomEntity.getMtHotelId(),switchCreateRoomEntity.getMtGoodId(),time);
                            long size=redisService.setSize("switch_hotel_room_is_down");
                            if(size<300){
                                redisService.add("switch_hotel_room_is_down",hotelId+"_"+pricesVo.getRoomId());
                            }
                            continue;
                        }
                        addPrice=(Integer) redisService.hmGet(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER,switchCreateRoomEntity.getMtHotelId());
                        //是否参与促销活动
                        addRate= (Double) redisService.hmGet(CommonConstants.SWITCH_HOTEL_ACTIVE_LIST_BY_OPEN_ACTIVE,switchCreateRoomEntity.getMtHotelId());
                        if(ObjectUtils.isEmpty(addRate)){
                            addRate=1.0;
                        }
                        double addPrices=0.00;
                        if(!ObjectUtils.isEmpty(addPrice)){
                            addPrices=addPrice.doubleValue()/100;
                        }
                        //标准价
                        String priceStr= (String) redisService.get(key);
                        Integer price2;
                        String[] prices=priceStr.split("_");
                        if(redisService.exists(key2)){
                            price2= (Integer) redisService.get(key2);
                        }else{
                            price2= Integer.valueOf(prices[0]);
                        }
                        priceMap = switchPushRoomService.getPriceV2(priceSetMap, price2, Integer.parseInt(prices[1]), null);
                        //实际美团的价格
                        double price = Double.parseDouble(priceMap.get("ctripPrice").toString());
                        //如果价格和美团的价格不一样
                        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
                        String qunar = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
                        String b2bChannel=StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
                        if(price!=pricesVo.getPrice()){
                            if(pricesVo.getPrice()<price) {
                                if(price-pricesVo.getPrice()<3.00){
                                    continue;
                                }
                               // SendUtils.dingMsgNotLog("二线"+time + "携程价格<美团价格" + "携程酒店id" + hotelId + "携程房型id" + pricesVo.getRoomId(), "美团的价格为" + price + "携程的价格为" + pricesVo.getPrice(), MessageEnums.genre.SWITCH_HOTEL_STATUS_AND_PRICE_NOTITY.getCode(), restTemplate);
                                //携程
                                roomDataEntityVo = new RoomDataEntityVo();
                                roomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                roomDataEntityVo.setStartDate(time);
                                roomDataEntityVo.setEndDate(time);
                                //去哪儿
                                qunarRoomDataEntityVo = new RoomDataEntityVo();
                                qunarRoomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                qunarRoomDataEntityVo.setStartDate(time);
                                qunarRoomDataEntityVo.setEndDate(time);
                                //b2b
                                b2bRoomDataEntityVo = new RoomDataEntityVo();
                                b2bRoomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                b2bRoomDataEntityVo.setStartDate(time);
                                b2bRoomDataEntityVo.setEndDate(time);
                                //channelA
                                channelRoomDataEntityVo = new RoomDataEntityVo();
                                channelRoomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                channelRoomDataEntityVo.setStartDate(time);
                                channelRoomDataEntityVo.setEndDate(time);
                                //携程价格实体
                                roomPriceModelVo = new RoomPriceModelVo();
                                roomPriceModelVo.setRoomPrice((price + addPrices + 0.01)/addRate);
                                roomPriceModelVo.setCurrency("CNY");
                                roomPriceModelVo.setChannel(channel);
                                roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
                                //去哪儿价格实体
                                qunarRoomPriceModelVo = new RoomPriceModelVo();
                                qunarRoomPriceModelVo.setRoomPrice((price + addPrices + 0.01)/addRate);
                                qunarRoomPriceModelVo.setCurrency("CNY");
                                qunarRoomPriceModelVo.setChannel(qunar);
                                qunarRoomDataEntityVo.setRoomPriceModel(qunarRoomPriceModelVo);
                                //b2b价格实体
                                b2bRoomPriceModelVo = new RoomPriceModelVo();
                                b2bRoomPriceModelVo.setRoomPrice((price + addPrices + 0.01)/addRate);
                                b2bRoomPriceModelVo.setCurrency("CNY");
                                b2bRoomPriceModelVo.setChannel(b2bChannel);
                                b2bRoomDataEntityVo.setRoomPriceModel(b2bRoomPriceModelVo);
                                roomDataEntitys.add(roomDataEntityVo);
                                roomDataEntitys.add(qunarRoomDataEntityVo);
                                roomDataEntitys.add(b2bRoomDataEntityVo);
                            }else{
                                if(pricesVo.getPrice()-price<3.00){
                                    continue;
                                }
                                //SendUtils.dingMsgNotLog("二线"+time + "携程价格>美团价格" + "携程酒店id" + hotelId + "携程房型id" + pricesVo.getRoomId(), "美团的价格为" + price + "携程的价格为" + pricesVo.getPrice(), MessageEnums.genre.SWITCH_HOTEL_STATUS_AND_PRICE_NOTITY.getCode(), restTemplate);
                                //携程
                                roomDataEntityVo = new RoomDataEntityVo();
                                roomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                roomDataEntityVo.setStartDate(time);
                                roomDataEntityVo.setEndDate(time);
                                //去哪儿
                                qunarRoomDataEntityVo = new RoomDataEntityVo();
                                qunarRoomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                qunarRoomDataEntityVo.setStartDate(time);
                                qunarRoomDataEntityVo.setEndDate(time);
                                //b2b
                                b2bRoomDataEntityVo = new RoomDataEntityVo();
                                b2bRoomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                b2bRoomDataEntityVo.setStartDate(time);
                                b2bRoomDataEntityVo.setEndDate(time);
                                //channelA
                                channelRoomDataEntityVo = new RoomDataEntityVo();
                                channelRoomDataEntityVo.setRoomId(pricesVo.getRoomId());
                                channelRoomDataEntityVo.setStartDate(time);
                                channelRoomDataEntityVo.setEndDate(time);
                                //携程价格实体
                                roomPriceModelVo = new RoomPriceModelVo();
                                roomPriceModelVo.setRoomPrice((price + addPrices + 0.01)/addRate);
                                roomPriceModelVo.setCurrency("CNY");
                                roomPriceModelVo.setChannel(channel);
                                roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
                                //去哪儿价格实体
                                qunarRoomPriceModelVo = new RoomPriceModelVo();
                                qunarRoomPriceModelVo.setRoomPrice((price + addPrices + 0.01)/addRate);
                                qunarRoomPriceModelVo.setCurrency("CNY");
                                qunarRoomPriceModelVo.setChannel(qunar);
                                qunarRoomDataEntityVo.setRoomPriceModel(qunarRoomPriceModelVo);
                                //b2b价格实体
                                b2bRoomPriceModelVo = new RoomPriceModelVo();
                                b2bRoomPriceModelVo.setRoomPrice((price + addPrices + 0.01)/addRate);
                                b2bRoomPriceModelVo.setCurrency("CNY");
                                b2bRoomPriceModelVo.setChannel(b2bChannel);
                                b2bRoomDataEntityVo.setRoomPriceModel(b2bRoomPriceModelVo);
                                roomDataEntitys.add(roomDataEntityVo);
                                roomDataEntitys.add(qunarRoomDataEntityVo);
                                roomDataEntitys.add(b2bRoomDataEntityVo);
                            }
                            //记录价格房态记录
                            SwitchHotelRoomPriceAndStatusLogEntity switchHotelRoomPriceAndStatusLogEntity=new SwitchHotelRoomPriceAndStatusLogEntity();
                            switchHotelRoomPriceAndStatusLogEntity.setCreateTime(new Date());
                            switchHotelRoomPriceAndStatusLogEntity.setDate(time);
                            switchHotelRoomPriceAndStatusLogEntity.setUpdateTime(new Date());
                            switchHotelRoomPriceAndStatusLogEntity.setHotelId(hotelId);
                            switchHotelRoomPriceAndStatusLogEntity.setRoomId(pricesVo.getRoomId());
                            switchHotelRoomPriceAndStatusLogEntity.setId(StringUtil.getUUID());
                            switchHotelRoomPriceAndStatusLogEntity.setMtGoodId(switchCreateRoomEntity.getMtGoodId());
                            switchHotelRoomPriceAndStatusLogEntity.setMtHotelId(switchCreateRoomEntity.getHotelId());
                            switchHotelRoomPriceAndStatusLogEntity.setMtPrice((int) (price*100));
                            switchHotelRoomPriceAndStatusLogEntity.setSwPrice((int) (pricesVo.getPrice()*100));
                            switchHotelRoomPriceAndStatusLogEntity.setRemark("价格");
                            switchHotelRoomPriceAndStatusLogEntity.setMtStatus(0);
                            switchHotelRoomPriceAndStatusLogEntity.setSwStatus(0);
                            switchHotelRoomPriceAndStatusLogEntities.add(switchHotelRoomPriceAndStatusLogEntity);
                        }
                    }
                    if(roomDataEntitys.size()>0){
                        batchPushRoomVo.setRoomDataEntitys(roomDataEntitys);
                        if(redisService.listSize(MeituanConstants.REDIS_CHANGE_GOODS_DATA_MANY_HOTEL)<500){
                            if(redisService.listSize(CommonConstants.SWITCH_CHECK_HOTEL_PRICE_AND_STATUS_REFRESH_PUSH)<1000){
                                redisService.lPush(CommonConstants.SWITCH_CHECK_HOTEL_PRICE_AND_STATUS_REFRESH_PUSH,JacksonUtil.objectToJson(batchPushRoomVo));
                            }
                        }
                    }
                }
            }
            //如果是vip->普通酒店，需要把后面几天的房态关掉
            String keyss="switch_vip_to_normal";
            int mtHotelId=0;
            //记录异常数据
            //获取房态接口
            BatchPushRoomVo batchPushRoomVo=new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(hotelId);
            List<RoomDataEntityVo> roomDataEntitys=new ArrayList<>();
            RoomDataEntityVo roomDataEntityVo;
            RoomStatusModelVo roomStatusModelVo;
            RoomInventoryModelVo roomInventoryModelVo;
            Result<List<ChannelRoomStatusVo>> result1=switchRoomPriceService.getRoomStatusDirect(getRoomPriceVo);
            List<ChannelRoomStatusVo> channelRoomStatusVos=result1.getData();
            if(!ObjectUtils.isEmpty(channelRoomStatusVos)&&channelRoomStatusVos.size()>0){
                for(ChannelRoomStatusVo channelRoomStatusVo:channelRoomStatusVos){
                    String time=DateUtil.switchDateParse(channelRoomStatusVo.getEffectDate());
                    SwitchCreateRoomEntity switchCreateRoomEntity=switchCreateRoomMapper.selectByHotelIdAndRoomId(hotelId,channelRoomStatusVo.getRoomId());
                    mtHotelId=switchCreateRoomEntity.getMtHotelId();
                    boolean f=redisService.isMember(keyss,mtHotelId);
                    String key=CallbackConstants.REDIS_KEY_CALLBACK_CHANGE_STATUS_HEAD+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_"+time;
                    if(!redisService.exists(key)){
                        long size=redisService.setSize("switch_hotel_room_is_down");
                        if(size<300){
                            redisService.add("switch_hotel_room_is_down",hotelId+"_"+channelRoomStatusVo.getRoomId());
                        }
                       // SendUtils.dingMsgNotLog("二线"+time+"无缓存数据"+"携程酒店id"+hotelId+"携程房型id"+channelRoomStatusVo.getRoomId(),"",MessageEnums.genre.SWITCH_HOTEL_STATUS_AND_PRICE_NOTITY.getCode(),restTemplate);
                       // log.info("=====美团的酒店id{}美团的产品id{}日期为{}无房态数据====",switchCreateRoomEntity.getMtHotelId(),switchCreateRoomEntity.getMtGoodId(),time);
                        continue;
                    }
                    int status= (int) redisService.get(key);
                    int status1=(status==1)?1:0;
                    if(status1!=channelRoomStatusVo.getSaleStatus()){
                        //如果携程是开房
                        if(channelRoomStatusVo.getSaleStatus()==1){
                            roomDataEntityVo=new RoomDataEntityVo();
                            roomDataEntityVo.setRoomId(channelRoomStatusVo.getRoomId());
                            roomDataEntityVo.setEndDate(time);
                            roomDataEntityVo.setStartDate(time);
                            roomStatusModelVo=new RoomStatusModelVo();
                            roomStatusModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                            roomStatusModelVo.setSaleStatus(0);
                            roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                            roomInventoryModelVo=new RoomInventoryModelVo();
                            roomInventoryModelVo.setPreservedQuantity(0);
                            roomInventoryModelVo.setPushPreservedType(4);
                            roomInventoryModelVo.setUnPreservedQuantity(1);
                            roomInventoryModelVo.setPushUnPreservedType(4);
                            roomInventoryModelVo.setAutoCloseRoom(1);
                            roomInventoryModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                            roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                            roomDataEntitys.add(roomDataEntityVo);
                            num++;
                           // SendUtils.dingMsgNotLog("二线"+time+"携程的开房美团关房"+"携程酒店id"+hotelId+"携程房型id"+channelRoomStatusVo.getRoomId(),"",MessageEnums.genre.SWITCH_HOTEL_STATUS_AND_PRICE_NOTITY.getCode(),restTemplate);
                        }else{
                            now=DateUtil.formatDate(DateUtil.getNextDays(-1),"yyyyMMdd");
                            //统计同开同关数据
                            String kes="switch_check_hotel_room_status_is_no_open"+now;
                            if(redisService.exists(kes)){
                                redisService.remove(kes);
                            }
                            kes="switch_check_hotel_room_status_is_no_open"+DateUtil.formatDate(DateUtil.getNextDays(0),"yyyyMMdd");
                            String str=hotelId+"_"+channelRoomStatusVo.getRoomId()+"_"+time;
                            Integer score= (Integer) redisService.hmGet(kes,str);
                            if(ObjectUtils.isEmpty(score)){
                                log.info("==========str不存在集合中=============");
                                score=1;
                            }else{
                                score++;
                            }
                            //如果超过2次推送，还未更新状态就说明携程直采关房了
                            if(score>2){
                                log.info("==========如果超过2次推送，还未更新状态就说明携程直采关房了=============");
                                redisService.add("switch_check_hotel_room_status_is_no_open",str);
                            }
                            redisService.hmSet(kes,str,score);
                            roomDataEntityVo=new RoomDataEntityVo();
                            roomDataEntityVo.setRoomId(channelRoomStatusVo.getRoomId());
                            roomDataEntityVo.setEndDate(time);
                            roomDataEntityVo.setStartDate(time);
                            roomStatusModelVo=new RoomStatusModelVo();
                            roomStatusModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                            roomStatusModelVo.setSaleStatus(1);
                            roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                            roomInventoryModelVo=new RoomInventoryModelVo();
                            roomInventoryModelVo.setPreservedQuantity(0);
                            roomInventoryModelVo.setPushPreservedType(4);
                            roomInventoryModelVo.setUnPreservedQuantity(1);
                            roomInventoryModelVo.setPushUnPreservedType(4);
                            roomInventoryModelVo.setAutoCloseRoom(1);
                            roomInventoryModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                            roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                            roomDataEntitys.add(roomDataEntityVo);
                           // SendUtils.dingMsgNotLog("二线"+time+"携程的关房美团开房"+"携程酒店id"+hotelId+"携程房型id"+channelRoomStatusVo.getRoomId(),"",MessageEnums.genre.SWITCH_HOTEL_STATUS_AND_PRICE_NOTITY.getCode(),restTemplate);
                        }
                        SwitchHotelRoomPriceAndStatusLogEntity switchHotelRoomPriceAndStatusLogEntity=new SwitchHotelRoomPriceAndStatusLogEntity();
                        //记录价格房态记录
                        switchHotelRoomPriceAndStatusLogEntity.setCreateTime(new Date());
                        switchHotelRoomPriceAndStatusLogEntity.setDate(time);
                        switchHotelRoomPriceAndStatusLogEntity.setUpdateTime(new Date());
                        switchHotelRoomPriceAndStatusLogEntity.setHotelId(hotelId);
                        switchHotelRoomPriceAndStatusLogEntity.setId(StringUtil.getUUID());
                        switchHotelRoomPriceAndStatusLogEntity.setMtGoodId(switchCreateRoomEntity.getMtGoodId());
                        switchHotelRoomPriceAndStatusLogEntity.setMtHotelId(switchCreateRoomEntity.getHotelId());
                        switchHotelRoomPriceAndStatusLogEntity.setMtPrice(0);
                        switchHotelRoomPriceAndStatusLogEntity.setSwPrice(0);
                        switchHotelRoomPriceAndStatusLogEntity.setRemark("房态");
                        switchHotelRoomPriceAndStatusLogEntity.setRoomId(channelRoomStatusVo.getRoomId());
                        switchHotelRoomPriceAndStatusLogEntity.setMtStatus(status);
                        switchHotelRoomPriceAndStatusLogEntity.setSwStatus(channelRoomStatusVo.getSaleStatus());
                        switchHotelRoomPriceAndStatusLogEntities.add(switchHotelRoomPriceAndStatusLogEntity);
                    }else{//如果一样的话,如果有记录重新删除
                        String str=hotelId+"_"+channelRoomStatusVo.getRoomId()+"_"+time;
                        String s="switch_check_hotel_room_status_is_no_open"+DateUtil.formatDate(DateUtil.getNextDays(0),"yyyyMMdd");
                        redisService.hmDel(s,str);
                    }
                    if(f){
                        log.info("========酒店ID{}vip->普通酒店需要关闭后面几天的房态===============",hotelId);
                        int vipDay=getDaysCommonBaseSetForVip()-1;
                        int normalDay=getDaysCommonBaseSetForNormal();
                        String endTimes=DateUtil.getDate(vipDay);
                        String statrTimes=DateUtil.getDate(normalDay);
                        RoomDataEntityVo roomDataEntityVo1=new RoomDataEntityVo();
                        roomDataEntityVo1.setRoomId(channelRoomStatusVo.getRoomId());
                        roomDataEntityVo1.setEndDate(endTimes);
                        roomDataEntityVo1.setStartDate(statrTimes);
                        roomStatusModelVo=new RoomStatusModelVo();
                        roomStatusModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                        roomStatusModelVo.setSaleStatus(0);
                        roomDataEntityVo1.setRoomStatusModel(roomStatusModelVo);
                        roomDataEntitys.add(roomDataEntityVo1);
                        log.info("======推送vip->普通酒店需要关闭后面几天的房态的数据为{}========",JacksonUtil.objectToJson(roomDataEntityVo1));
                    }
                }
            }
            if(roomDataEntitys.size()>0){
                batchPushRoomVo.setRoomDataEntitys(roomDataEntitys);
                if(redisService.listSize(MeituanConstants.REDIS_CHANGE_GOODS_DATA_MANY_HOTEL)<500){
                    if(redisService.listSize(CommonConstants.SWITCH_CHECK_HOTEL_PRICE_AND_STATUS_REFRESH_PUSH)<1000){
                        redisService.lPush(CommonConstants.SWITCH_CHECK_HOTEL_PRICE_AND_STATUS_REFRESH_PUSH,JacksonUtil.objectToJson(batchPushRoomVo));
                    }
                }
            }
            String tableName="switch_hotel_room_price_and_status_log_"+DateUtil.formatDate(DateUtil.getNextDays(0),"yyyyMMdd");
            if(switchHotelRoomPriceAndStatusLogEntities.size()>0){
                switchHotelRoomPriceAndStatusLogMapper.insertData(tableName,switchHotelRoomPriceAndStatusLogEntities);
            }
            redisService.set(keys,num);
           // redisService.removeSetElt(keyss,mtHotelId);
            //电话预警
            String key="switch_hotel_room_status_and_price_no_similar";
            int phoneNum=2000;
            if(redisService.exists(key)){
                phoneNum=(int) redisService.get(key);
            }
            if(num>=phoneNum){
                String url =  CommonUrlConstants.MSG_HOST+"/message/sendVoiceToUser";
                Map<String, String> param = new HashMap<>();
                param.put("content", "今日超过2000条价格房态出现问题了，请前去排查");
                param.put("genre", "0");
                switchRestTempaleUtilsService.sendPostRequesToMsg(url, param);
                redisService.remove(keys);
            }
        }
    }
    /**
     * 获取普通酒店天数
     * @return
     */
    public Integer getDaysCommonBaseSetForNormal() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("getDaysCommonBaseSetForNormal获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询3天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 3;//有异常默认3天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }
        return returnDays;
    }
    /**
     * 获取优势酒店天数
     * @return
     */
    public Integer getDaysCommonBaseSetForVip() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("getDaysCommonBaseSetForVip获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询5天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 5;//有异常默认5天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }

        return returnDays;
    }
    /***
     * @Author: lmf
     * @Date: 2021/3/2
     * 获取价格公式,如果有分配就使用分配的，没有就是使用默认的
     */
    private Map<String, List<SwitchPriceBaseSetEntity>> getOnlinePriceSetByData(int swHotelId, Map<String, List<SwitchPriceBaseSetEntity>> switchPriceBaseSetMap) {
        String keys=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByCtripChannel;
        int day=0;
        if(redisService.exists(CommonConstants.SWITCH_PRICE_SET_PRICE_TIME)){
            Integer time= (Integer) redisService.get(CommonConstants.SWITCH_PRICE_SET_PRICE_TIME);
            Calendar calendar=Calendar.getInstance();
            int hour=calendar.get(Calendar.HOUR_OF_DAY);
            if(hour>=time){
                day=1;
            }
        }
        String str= (String) redisService.hmGet(keys,swHotelId+ SwitchChannelNameEnums.CTRIP.getName());
        if(!StringUtils.isEmpty(str)){
            switchPriceBaseSetEntityByCtripChannel=JacksonUtil.jsonToList(str,SwitchPriceBaseSetEntity.class);
        }else{
            switchPriceBaseSetEntityByCtripChannel=switchPriceBaseSetMapper.selectByChannelNameAndHotelRelation(swHotelId,SwitchChannelNameEnums.CTRIP.getName(),day);
        }
        str= (String) redisService.hmGet(keys,swHotelId+ SwitchChannelNameEnums.QUNAR.getName());
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByqunarChannel;
        if(!StringUtils.isEmpty(str)){
            switchPriceBaseSetEntityByqunarChannel=JacksonUtil.jsonToList(str,SwitchPriceBaseSetEntity.class);
        }else{
            switchPriceBaseSetEntityByqunarChannel=switchPriceBaseSetMapper.selectByChannelNameAndHotelRelation(swHotelId,SwitchChannelNameEnums.CTRIP.getName(),day);
        }
        if(!ObjectUtils.isEmpty(switchPriceBaseSetEntityByCtripChannel)&&switchPriceBaseSetEntityByCtripChannel.size()>0){
            switchPriceBaseSetMap.put(SwitchChannelNameEnums.CTRIP.getName(),switchPriceBaseSetEntityByCtripChannel);
            redisService.hmSet(keys,swHotelId+ SwitchChannelNameEnums.CTRIP.getName(),JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel));
        }
        if(!ObjectUtils.isEmpty(switchPriceBaseSetEntityByqunarChannel)&&switchPriceBaseSetEntityByqunarChannel.size()>0){
            switchPriceBaseSetMap.put(SwitchChannelNameEnums.QUNAR.getName(),switchPriceBaseSetEntityByqunarChannel);
            redisService.hmSet(keys,swHotelId+ SwitchChannelNameEnums.QUNAR.getName(),JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel));
        }
        return switchPriceBaseSetMap;
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/2
     * 获取有订单的酒店的所有产品的取消规则
     */
    @Override
    public XSSFWorkbook getOrderHotelCancelRule() {
        List<Integer> hotelIds=switchHotelUpMapper.getOrderHotelCancelRule();
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("cancelRule");//创建一张表
        Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("酒店id");//第一列
        titleRow.createCell(1).setCellValue("房型id");
        titleRow.createCell(2).setCellValue("房型名称");
        titleRow.createCell(3).setCellValue("取消规则");
        int cell=1;
        for(Integer hotelId:hotelIds){
            List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(hotelId);
            for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
                Row row = sheet.createRow(cell);//从第二行开始保存数据
                row.createCell(0).setCellValue(switchCreateRoomEntity.getHotelId());
                row.createCell(1).setCellValue(switchCreateRoomEntity.getRoomId());//将数据库的数据遍历出来
                row.createCell(2).setCellValue(switchCreateRoomEntity.getRoomName());
                String key=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_0";
                if(redisService.exists(key)){
                    row.createCell(3).setCellValue("不可取消");
                }
                key=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_1";
                if(redisService.exists(key)){
                    String cancelRule= (String) redisService.get(key);
                    String[] cannel=cancelRule.split("_");
                    row.createCell(3).setCellValue(cannel[0]+"天"+cannel[1]+"之前免费取消");
                }else{
                    row.createCell(3).setCellValue("不可取消");
                }
                cell++;
            }
           /* List<Integer> roomIds=new ArrayList<>();
            roomIds.add(980210812);
            Map<String, Object> map = new HashMap<>();
            map.put("hotelId", 60098059);
            map.put("roomIds",roomIds);
            String[] channels=new String[]{"ctrip"};
            map.put("channels",channels);
            map.put("returnAllRooms",false);
            Result<List<RoomSaleRuleReturnVo>>  result=switchBasicRoomTypeService.getRoomSaleRule(map);
            log.info("===========返回的数据为{}====",result);
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
        }
        return wb;
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/5
     * 设置定点售卖功能
     * @param switchFixPointSetEntity
     */
    @Override
    public Result<Object> setHotelSaleTime(SwitchFixPointSetEntity switchFixPointSetEntity) {
        log.info("==========定点售卖的数据为{}=======",switchFixPointSetEntity);
        //1.先判断是否有数据,如果有就进行更新
        SwitchFixPointSetEntity switchFixPointSetEntity1=switchFixPointSetMapper.selectFixPointSetInfo();
        if(ObjectUtils.isEmpty(switchFixPointSetEntity1)){
            int flag=switchFixPointSetMapper.insert(switchFixPointSetEntity);
            if(flag>0){
                return new Result<>();
            }else{
                return new Result<>("设置失败");
            }
        }else{
            Example example=new Example(SwitchFixPointSetEntity.class);
            Example.Criteria criteria=example.createCriteria();
            criteria.andEqualTo("id",switchFixPointSetEntity.getId());
            int flag=switchFixPointSetMapper.updateByExample(switchFixPointSetEntity,example);
            if(flag>0){
                return new Result<>();
            }else{
                return new Result<>("设置失败");
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/23
     * 获取定点售卖信息
     */
    @Override
    public Result<Object> getHotelSaleTime() {
        SwitchFixPointSetEntity switchFixPointSetEntity1=switchFixPointSetMapper.selectFixPointSetInfo();
        return new Result<>(switchFixPointSetEntity1);
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/23
     * 对所有的酒店设置定点售卖
     */
    @Override
    public Result<Object> pushFixPoint() {
        List<Integer> list=switchHotelUpMapper.selectSaleHotelList();
        List<List<Integer>> hotelIds=ListUtils.parititon(list,50);
        SwitchFixPointSetEntity switchFixPointSetEntity=switchFixPointSetMapper.selectFixPointSetInfo();
        for(List<Integer> hotelList:hotelIds){
            Map<String, Object> updateChannelVoMap = new HashMap<>();
            updateChannelVoMap.put("hotelIDs", hotelList);
            updateChannelVoMap.put("cBookable", 3);
            updateChannelVoMap.put("qBookable", 3);
            updateChannelVoMap.put("channelABookable", 3);
            updateChannelVoMap.put("b2bBookable", 3);
            List<SupplierTimeSaleInfoVo> supplierTimeSaleInfoVos=new ArrayList<>();
            if(switchFixPointSetEntity.getWeek()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("1111111");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek2()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime2());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime2());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay2());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("1000000");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek3()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime3());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime3());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay3());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("0100000");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek4()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime4());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime4());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay4());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("0010000");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek5()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime5());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime5());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay5());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("0001000");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek6()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime6());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime6());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay6());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("0000100");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek7()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime7());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime7());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay7());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("0000010");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            if(switchFixPointSetEntity.getWeek8()==1){
                SupplierTimeSaleInfoVo supplierTimeSaleInfoVo=new SupplierTimeSaleInfoVo();
                supplierTimeSaleInfoVo.setStartTime(switchFixPointSetEntity.getStartTime8());
                supplierTimeSaleInfoVo.setEndTime(switchFixPointSetEntity.getEndTime8());
                supplierTimeSaleInfoVo.setEndTimeType(switchFixPointSetEntity.getDay8());
                supplierTimeSaleInfoVo.setStartDate(switchFixPointSetEntity.getStartDate());
                supplierTimeSaleInfoVo.setEndDate(switchFixPointSetEntity.getEndDate());
                supplierTimeSaleInfoVo.setApplyWeek("0000001");
                supplierTimeSaleInfoVos.add(supplierTimeSaleInfoVo);
            }
            updateChannelVoMap.put("supplierTimeSaleInfoList",supplierTimeSaleInfoVos);
            Result<Object> result= switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
        }
        return null;
    }
    /****
     * @Author: lmf
     * @Date: 2021/2/26
     * 酒店进行公式分类
     * @param genre
     */
    @Override
    public Result<Object> allotHotelAndFormula(Integer genre) {
        if(genre==0){
            //获取第一类的公式
            List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectFormualList(1);
            log.info("===========第一类公式长度为{}=======",switchPriceBaseSetEntities.size());
            //获取有订单的酒店数据
            List<Integer> haveOrderHotelList=switchHotelUpMapper.selectHaveOrderHotelList();
            log.info("=======有订单的酒店id为{}=====",haveOrderHotelList);
            for(Integer hotelId:haveOrderHotelList){
                //为有订单的酒店绑定第一个价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities=new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities=new ArrayList<>();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity=new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1=switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)){
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setFormula(1);
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity=new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(1);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                    int flag=switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到缓存中
                    if(flag>0){
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                        //关联价格公式
                  /* String key=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                   String ctripKey=key+hotelId+ SwitchChannelNameEnums.CTRIP.getName();
                   List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByCtripChannel=switchPriceBaseSetMapper.selectByChannelNameAndRelation(SwitchChannelNameEnums.CTRIP.getName(),hotelId);
                   redisService.set(ctripKey,JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel));
                   String qunarKey=key+hotelId+SwitchChannelNameEnums.QUNAR.getName();
                   List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByQunarChannel=switchPriceBaseSetMapper.selectByChannelNameAndRelation(SwitchChannelNameEnums.QUNAR.getName(),hotelId);
                   redisService.set(qunarKey,JacksonUtil.objectToJson(switchPriceBaseSetEntityByQunarChannel));*/
                    }
                }
            }
            //获取第二类公式数据
            switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectFormualList(2);
            log.info("===========第二类公式长度为{}=======",switchPriceBaseSetEntities.size());
            //获取有订单的酒店数据
            List<Integer> haveNoOrderHotelList=switchHotelUpMapper.selectHaveNoOrderHotelList();
            log.info("===========没有订单的酒店长度为{}=======",haveNoOrderHotelList.size());
            for(Integer hotelId:haveNoOrderHotelList){
                //为有订单的酒店绑定第一个价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities=new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities=new ArrayList<>();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity=new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1=switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)){
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setFormula(2);
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity=new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(2);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                    int flag=switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到缓存中
                    if(flag>0){
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                   /* //关联价格公式
                    String key=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    String ctripKey=key+hotelId+ SwitchChannelNameEnums.CTRIP.getName();
                    List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByCtripChannel=switchPriceBaseSetMapper.selectByChannelNameAndRelation(SwitchChannelNameEnums.CTRIP.getName(),hotelId);
                    redisService.set(ctripKey,JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel));
                    String qunarKey=key+hotelId+SwitchChannelNameEnums.QUNAR.getName();
                    List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByQunarChannel=switchPriceBaseSetMapper.selectByChannelNameAndRelation(SwitchChannelNameEnums.QUNAR.getName(),hotelId);
                    redisService.set(qunarKey,JacksonUtil.objectToJson(switchPriceBaseSetEntityByQunarChannel));*/
                    }
                }
            }
        }else if(genre==1){//从公式二获取无订单的酒店数据
            // 第三类公式,已经绑定过第二类公式，但是仍然没有订单的酒店
            List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectFormualList(3);
            log.info("===========第三类公式长度为{}=======",switchPriceBaseSetEntities.size());
            //获取有订单的酒店数据
            List<Integer> haverRelationOrderHotelList=switchHotelUpMapper.selectNoOrderHotelListByReation(2);
            log.info("===========有公式但是没有订单的酒店长度为{}=======",haverRelationOrderHotelList.size());
            for(Integer hotelId:haverRelationOrderHotelList){
                //先删除已经绑定的第二级价格公式
                int result=switchHotelPriceSetRelationMapper.deleteByHotelIdAndFormula(hotelId,2);
                if(result>0){
                    String keys=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.CTRIP.getName());
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.QUNAR.getName());
                }
                //绑定价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities=new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities=new ArrayList<>();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity=new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1=switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)){
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setFormula(3);
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity=new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(3);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                    int flag=switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到缓存中
                    if(flag>0){
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                    }
                }
            }
        }else {
            // 第三类公式,已经绑定过第二类公式，但是仍然没有订单的酒店
            List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities = switchPriceBaseSetMapper.selectFormualList(4);
            log.info("===========第四类公式长度为{}=======", switchPriceBaseSetEntities.size());
            //获取有订单的酒店数据
            List<Integer> haverRelationOrderHotelList = switchHotelUpMapper.selectNoOrderHotelListByReation(3);
            log.info("===========有公式但是没有订单的酒店长度为{}=======", switchPriceBaseSetEntities.size());
            for (Integer hotelId : haverRelationOrderHotelList) {
                //先删除已经绑定的第二级价格公式
                int result = switchHotelPriceSetRelationMapper.deleteByHotelIdAndFormula(hotelId, 3);
                if (result > 0) {
                    String keys = CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.CTRIP.getName());
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.QUNAR.getName());
                }
                //绑定价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities = new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities = new ArrayList<>();
                for (SwitchPriceBaseSetEntity switchPriceBaseSetEntity : switchPriceBaseSetEntities) {
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity = new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1 = switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if (!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)) {
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setFormula(3);
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity = new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(3);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if (!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities) && switchHotelPriceSetRelationEntities.size() > 0) {
                    int flag = switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到缓存中
                    if (flag > 0) {
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                    }
                }
            }
        }
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/3/8
     * 清除酒店的价格公式
     */
    @Override
    public Result<Object> removeHotelPriceSetCache() {
        String key="switch_online_price_sets_up_by_"+ SwitchChannelNameEnums.CTRIP.getName();
        String qunarKey="switch_online_price_sets_up_by_"+SwitchChannelNameEnums.QUNAR.getName();
        if(redisService.exists(key)){
            redisService.remove(key);
        }
        if(redisService.exists(qunarKey)){
            redisService.remove(qunarKey);
        }
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectAll();
        for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            executorService.execute(new SwitchRemoveFormualThread(switchPriceBaseSetEntity.getId()));
            executorService.shutdown();
        }
        return null;
    }


    /***
     * @Author: lmf
     * @Date: 2021/3/8
     * 清除缓存数据
     */
    class SwitchRemoveFormualThread implements Runnable{
        private Integer id;

        public SwitchRemoveFormualThread(Integer id) {
            this.id = id;
        }
        @Override
        public void run() {
            //如果是二类或者三类要删除缓存
            Example example=new Example(SwitchHotelPriceSetRelationEntity.class);
            Example.Criteria criteria=example.createCriteria();
            criteria.andEqualTo("sid",this.id);
            List<SwitchHotelPriceSetRelationEntity>  switchHotelPriceSetRelationEntities=switchHotelPriceSetRelationMapper.selectByExample(example);
            if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                for(SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity:switchHotelPriceSetRelationEntities){
                    //String keys=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    //String ctripKey=keys+switchHotelPriceSetRelationEntity.getHotelId()+ SwitchChannelNameEnums.CTRIP.getName();
                 /*   if(redisService.exists(ctripKey)){
                        redisService.remove(ctripKey);
                    }*/
                    redisService.hmDel(CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION,switchHotelPriceSetRelationEntity.getHotelId()+ SwitchChannelNameEnums.CTRIP.getName());
                    // String qunarKeys=keys+switchHotelPriceSetRelationEntity.getHotelId()+ SwitchChannelNameEnums.QUNAR.getName();
                  /*  if(redisService.exists(qunarKeys)){
                        redisService.remove(qunarKeys);
                    }*/
                    redisService.hmDel(CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION,switchHotelPriceSetRelationEntity.getHotelId()+ SwitchChannelNameEnums.QUNAR.getName());
                }
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/3/24
     * 创建表
     */
    @Override
    public Result<Object> createTable() {
        String nowDate = DateUtil.formatDate(DateUtil.getNextDays(1),"yyyyMMdd");
        String table=SWITCH_HOTEL_ROOM_PRICE_AND_STATUS_LOG_TABLE+nowDate;
        //美团异步推送价格表
        String sql = "create table if not exists " + table + "(\n" +
                " `id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
                "  `hotel_id` int(11) NOT NULL DEFAULT 0 COMMENT '携程酒店id',\n" +
                "  `room_id` int(11) NOT NULL DEFAULT 0 COMMENT '携程售卖房型id',\n" +
                "  `mt_hotel_id` int(11) NOT NULL DEFAULT 0 COMMENT '美团酒店id',\n" +
                "  `mt_good_id` int(11) NOT NULL DEFAULT 0 COMMENT '美团产品id',\n" +
                "  `sw_price` int(6) NOT NULL DEFAULT 0 COMMENT '携程价格',\n" +
                "  `mt_price` int(6) NOT NULL DEFAULT 0 COMMENT '美团价格',\n" +
                "  `sw_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '房态 0 满房 1 有房',\n" +
                "  `mt_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '美团房态',\n" +
                "  `date` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '日期',\n" +
                "  `remark` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',\n" +
                "  `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',\n" +
                "  `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',\n" +
                "  INDEX `room_id`(`room_id`) USING BTREE,\n" +
                "  INDEX `hotel_id`(`hotel_id`) USING BTREE,\n" +
                "  INDEX `mt_good_id`(`mt_good_id`) USING BTREE,\n" +
                "  INDEX `room_id_hotel_id`(`room_id`, `hotel_id`) USING BTREE,\n" +
                "  INDEX `date`(`date`) USING BTREE\n" +
                ") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;";
        switchHotelRoomPriceAndStatusLogMapper.createTable(sql);
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/4/7
     * 获取参与活动的酒店列表
     */
    @Override
    public Result<Object> getJoinActiveHotelList() {
        //美团那边添加低价的时候用
        if(redisService.exists(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST)){
            redisService.remove(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST);
        }
        //记录推送天天特价的酒店
   /*     if(redisService.exists(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER)){
            redisService.remove(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER);
        }*/
        int num=300;
        String key=CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_NUM;
        if(redisService.exists(key)){
            num= (int) redisService.get(key);
        }
        List<Integer> list=switchHotelUpMapper.selectJoinActiveHotelList(num);
        key=CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER;
        Integer price=5000;
        if(redisService.exists(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_PRICE)){
            price= (Integer) redisService.get(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_PRICE);
        }
        String finalKey = key;
        Integer finalPrice = price;
        list.forEach(e->{
            Integer hotelId= (Integer) redisService.hmGet(finalKey,e);
            if(ObjectUtils.isEmpty(hotelId)){
                log.info("======新的酒店加入天天特价缓存中===============");
                redisService.hmSet(finalKey,e, finalPrice);
            }else{
                log.info("======已存在天天特价缓存中===============");
            }
            //删除key名
            int day=3;
            if(redisService.isMember(CommonConstants.SWITCH_SALE_HOTEL_VIP,e)){
                day=getDaysCommonBaseSetForVip();
            }else{
                day=getDaysCommonBaseSetForNormal();
            }
            List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByMtHotelId(e);
            int finalDay = day;
            switchCreateRoomEntities.forEach(e1->{
                for(int i = 0; i< finalDay; i++){
                    //删除价格
                    String key2=CallbackConstants.REDIS_KEY_CALLBACK_CHANGE_PRICE_HEAD+e1.getMtHotelId()+"_"+e1.getMtGoodId()+"_"+ DateUtil.getDateAfter(new Date(),i);
                    if(redisService.exists(key2)){
                        redisService.remove(key2);
                    }
                }
            });
        });
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/4/9
     */
    @Override
    public Result<Object> initSaleHotelRoomToCache() {
        List<Integer> mtHotelIds=switchCreateRoomMapper.selectSaleHotelList();
        mtHotelIds.forEach(e->{
            List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByMtHotelId(e);
            List<Integer> roomIds=new ArrayList<>();
            switchCreateRoomEntities.forEach(e1->{
                roomIds.add(Integer.valueOf(e1.getMtRoomId()));
            });
            redisService.hmSet(CommonConstants.SWITCH_SALE_HOTEL_ROOM_LIST,e,roomIds);
        });
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/4/14
     * 初始化在售酒店房型到缓存
     */
    @Override
    public Result<Object> initSaleHotelRoomWindowToCache() {
        List<SwitchHotelUpEntity> switchHotelUpEntities=switchHotelUpMapper.selectSaleHotel();
        switchHotelUpEntities.forEach(e->{
            Result<Map<String, SwitchHotelRoomStaticInfoVo>> mapResult=switchBasicRoomTypeService.getHotelRoomStaticInfoList(e.getHotelId(),e.getMasterHotelId());
            Map<String, SwitchHotelRoomStaticInfoVo> data=mapResult.getData();
            if(!MapUtils.isEmpty(data)){
                data.forEach((k,v)->{
                    Integer mtWindow;
                    String window= v.getHasWindow();
                    if(window.equals("2")||StringUtil.isBlank(window)||window.equals("4")||window.equals("5")||window.equals("6")||window.equals("7")){
                        mtWindow=0;
                    }else if(window.equals("1")){
                        mtWindow=1;
                    }else{
                        mtWindow=2;
                    }
                    SwitchCreateRoomEntity switchCreateRoomEntity=switchCreateRoomMapper.selectMtHotelIdAndMtRoomIdByHotelId(e.getHotelId(),v.getBasicRoomTypeId());
                    if(!ObjectUtils.isEmpty(switchCreateRoomEntity)){
                        String key=CommonConstants.SWITCH_CREATE_ROOM_WINDOW_TYPE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtRoomId();
                        redisService.set(key,mtWindow);
                        log.info("=======key的值为{},有窗无窗为{}==",key,window);
                    }else{
                        //2.根据母酒店id+母物理房型id 从房型匹配表获取美团的酒店id+美团的房型id
                        String mtRoomId = "";
                        Map<String, Integer> params = new HashMap<>();
                        //携程母物理房型id
                        params.put("roomId", v.getMasterBasicRoomTypeId());
                        //母酒店id
                        params.put("masterHotelId", v.getMasterHotelId());
                        params.put("line",2);
                        //3.根据母酒店id+根据母物理房型id 获取对应的美团的酒店id + 美团的房型id
                        String url = CommonUrlConstants.COMPARE_HOST + "/" + CompareRequestUrlEnums.GET_HOTEL_BASIC_ROOM_INFO.getUrl();
                        CompareHotelBasicRoom compareHotelBasicRoom=new CompareHotelBasicRoom();
                        Result<CompareHotelBasicRoom> result = switchRestTempaleUtilsService.sendPostRequestByGetSwitchHotelIdAndRoomId(url, params);
                        if (result.getCode() == CommonConstants.SUCCESS) {
                            log.info("=====请求获取效验房型控制器成功,美团的房型id为:{}=======", result.getData());
                            compareHotelBasicRoom=result.getData();
                        }
                        if(!ObjectUtils.isEmpty(compareHotelBasicRoom)){
                            mtRoomId=compareHotelBasicRoom.getMtHotelRoomId();
                            String key=CommonConstants.SWITCH_CREATE_ROOM_WINDOW_TYPE+compareHotelBasicRoom.getMtHotelId()+"_"+mtRoomId;
                            redisService.set(key,mtWindow);
                            log.info("=======key的值为{},有窗无窗为{}==",key,window);
                        }
                    }
                });
                try {
                    Thread.sleep(7000);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
            }
        });
        return null;
    }
    /***
     * @Author: lmf
     * @Date: 2021/4/23
     * 更新价格房态
     */
    public Result<Object> refreshPushRoomStatusAndPrice(){
        if(redisService.listSize(CommonConstants.SWITCH_CHECK_HOTEL_PRICE_AND_STATUS_REFRESH_PUSH)==0){
            return new Result<>();
        }
        long size=redisService.listSize(MeituanConstants.REDIS_CHANGE_GOODS_DATA_MANY_HOTEL);
        int num=1;
        if(size<10){
            num=12;
        }
        for(int i=0;i<num;i++){
            String jsonStr= (String) redisService.lPop(CommonConstants.SWITCH_CHECK_HOTEL_PRICE_AND_STATUS_REFRESH_PUSH);
            if(StringUtils.isEmpty(jsonStr)){
                break;
            }
            BatchPushRoomVo batchPushRoomVo=JacksonUtil.parse(jsonStr,BatchPushRoomVo.class);
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            log.info("=====调用携程接口，返回的数据为{}=====",JSONUtils.toJSONString(result.getData()));
        }

        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2021/4/27
     * 获取上架的酒店列表
     */
    @Override
    public XSSFWorkbook exportHotel(Integer num) {
        List<Integer> hotelIds=switchHotelUpMapper.getCanSaleHotelList(num);
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("uphotel");//创建一张表
        Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("酒店");//第一列
        titleRow.createCell(1).setCellValue("酒店ID");
        int cell=1;
        for(Integer hotelId:hotelIds){
            Row row = sheet.createRow(cell);//从第二行开始保存数据
            row.createCell(0).setCellValue("");
            row.createCell(1).setCellValue(hotelId);//将数据库的数据遍历出来
            cell++;
        }
        return wb;
    }

    /**
     * 初始化酒店数据 供美团异步调佣
     * @return
     */
    @Override
    public Result<Object> initHotelData() {
        List<Integer> list = switchHotelUpMapper.getUpHotelAsc();
        if(redisService.exists("is_open_four_hotel_list")){
            int size=40000-list.size();
            List<Integer> replaceList=switchHotelUpMapper.replaceList();
            for(int i=0;i<size;i++){
                Integer mtHotelId=replaceList.stream().findFirst().orElse(null);
                list.add(mtHotelId);
                replaceList.remove(mtHotelId);
            }
        }
        list.forEach(e->{
            redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,e);
        });
       /* if(redisService.exists(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST)){
            redisService.remove(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST);
        }
        list.forEach(e->{
            redisService.add(CommonConstants.SWITCH_SALE_HOTEL_TO_PRICE_LIST,e);
        });*/
        return new Result<>(GsonUtils.GsonString(list), "success");
    }
    /**
     * 获取酒店状态
     * @return
     */
    @Override
    public Result<Object> getHolelStatus() {
        Map<String,Object> param=new HashMap<>();
        param.put("hotelID",70465615);
        DltHotelEntityVo dltHotelEntityVo=switchSubHotelInfoService.getStuHotelInfo(param);
        return new Result<>(dltHotelEntityVo.getCBookable());
    }
    /**
     * @Author: lmf
     * @Date: 2021/5/26
     * 针对有公式的酒店进行公式降级，如果到达最低等级不进行调价
     * 每个月，月初进行调整
     */
    @Override
    public Result<Object> hotelFormualLadderDown() {
        //获取公式一 无订单的酒店数据
        List<Integer> formula_one=switchHotelUpMapper.selectFormualLadderDownHotelId(1);
        //获取公式二 无订单酒店数据
        List<Integer> formula_two=switchHotelUpMapper.selectFormualLadderDownHotelId(2);
        //获取公式三 无订单酒店数据
        List<Integer> formula_there=switchHotelUpMapper.selectFormualLadderDownHotelId(3);
        log.info("======公式一无订单的酒店有{}家==============",formula_one.size());
        log.info("======公式二无订单的酒店有{}家==============",formula_two.size());
        log.info("======公式三无订单的酒店有{}家==============",formula_there.size());
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectFormualList(2);
        if(formula_one.size()>0){
            log.info("========公式一开始进行调整价格=====================");
            for(Integer hotelId:formula_one){
                //先删除已经绑定的第二级价格公式
                int result=switchHotelPriceSetRelationMapper.deleteByHotelIdAndFormula(hotelId,1);
                if(result>0){
                    String keys=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.CTRIP.getName());
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.QUNAR.getName());
                }
                //绑定价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities=new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities=new ArrayList<>();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity=new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1=switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)){
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setFormula(2);
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity=new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(2);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                    int flag=switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到记录中
                    if(flag>0){
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                    }
                }
            }
        }
        log.info("============开始调整第二类的订单===================");
        if(formula_two.size()>0){
            log.info("========公式二开始进行调整价格=====================");
            //获取公式3
            switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectFormualList(3);
            for(Integer hotelId:formula_two){
                //先删除已经绑定的第二级价格公式
                int result=switchHotelPriceSetRelationMapper.deleteByHotelIdAndFormula(hotelId,2);
                if(result>0){
                    String keys=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.CTRIP.getName());
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.QUNAR.getName());
                }
                //绑定价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities=new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities=new ArrayList<>();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity=new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1=switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)){
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setFormula(3);
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity=new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(3);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                    int flag=switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到记录中
                    if(flag>0){
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                    }
                }
            }
        }
        log.info("============开始调整第三类的订单===================");
        if(formula_there.size()>0){
            log.info("========公式三开始进行调整价格=====================");
            //获取公式4
            switchPriceBaseSetEntities=switchPriceBaseSetMapper.selectFormualList(4);
            for(Integer hotelId:formula_there){
                //先删除已经绑定的第三级价格公式
                int result=switchHotelPriceSetRelationMapper.deleteByHotelIdAndFormula(hotelId,3);
                if(result>0){
                    String keys=CommonConstants.SWITCH_HOTEL_PRICE_SET_RELATION;
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.CTRIP.getName());
                    redisService.hmDel(keys,hotelId+ SwitchChannelNameEnums.QUNAR.getName());
                }
                //绑定价格公式
                List<SwitchHotelPriceSetRelationEntity> switchHotelPriceSetRelationEntities=new ArrayList<>();
                List<SwitchHotelPriceSetRelationLogEntity> switchHotelPriceSetRelationLogEntities=new ArrayList<>();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity=new SwitchHotelPriceSetRelationEntity();
                    switchHotelPriceSetRelationEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationEntity.setSid(switchPriceBaseSetEntity.getId());
                    SwitchHotelPriceSetRelationEntity switchHotelPriceSetRelationEntity1=switchHotelPriceSetRelationMapper.selectOne(switchHotelPriceSetRelationEntity);
                    if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntity1)){
                        continue;
                    }
                    switchHotelPriceSetRelationEntity.setFormula(4);
                    switchHotelPriceSetRelationEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationEntities.add(switchHotelPriceSetRelationEntity);
                    SwitchHotelPriceSetRelationLogEntity switchHotelPriceSetRelationLogEntity=new SwitchHotelPriceSetRelationLogEntity();
                    switchHotelPriceSetRelationLogEntity.setCreateTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setHotelId(hotelId);
                    switchHotelPriceSetRelationLogEntity.setId(StringUtil.getUUID());
                    switchHotelPriceSetRelationLogEntity.setModifyTime(new Date());
                    switchHotelPriceSetRelationLogEntity.setFormula(4);
                    switchHotelPriceSetRelationLogEntity.setRemark("");
                    switchHotelPriceSetRelationLogEntity.setSid(switchPriceBaseSetEntity.getId());
                    switchHotelPriceSetRelationLogEntities.add(switchHotelPriceSetRelationLogEntity);
                }
                if(!ObjectUtils.isEmpty(switchHotelPriceSetRelationEntities)&&switchHotelPriceSetRelationEntities.size()>0){
                    int flag=switchHotelPriceSetRelationMapper.insertList(switchHotelPriceSetRelationEntities);
                    //把价格公式保存到记录中
                    if(flag>0){
                        switchHotelPriceSetRelationLogMapper.insertList(switchHotelPriceSetRelationLogEntities);
                    }
                }
            }
        }
        log.info("=============阶梯降价完成===================================");
        return new Result<>();
    }
    /**
     * 记录直采满房美团有房的数据
     */
    @Override
    public Result<Object> recordRoomStatusLog() {
        String keys="switch_check_hotel_room_status_is_no_open";
        Set<Object> set=redisService.getMembers(keys);
        if(!CollectionUtils.isEmpty(set)){
            set.forEach(e->{
                log.info("==========e的值为{}======",e);
                String[] s=e.toString().split("_");
                Example example=new Example(SwitchRoomStatusLogEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("hotelId",Integer.valueOf(s[0]));
                criteria.andEqualTo("roomId",Integer.valueOf(s[1]));
                criteria.andEqualTo("date",s[2]);
                SwitchRoomStatusLogEntity switchRoomStatusLogEntity1=switchRoomStatusLogMapper.selectOneByExample(example);
                if(ObjectUtils.isEmpty(switchRoomStatusLogEntity1)){
                    SwitchRoomStatusLogEntity switchRoomStatusLogEntity=new SwitchRoomStatusLogEntity();
                    switchRoomStatusLogEntity.setHotelId(Integer.valueOf(s[0]));
                    switchRoomStatusLogEntity.setRoomId(Integer.valueOf(s[1]));
                    switchRoomStatusLogEntity.setDate(s[2]);
                    switchRoomStatusLogMapper.insert(switchRoomStatusLogEntity);
                }
                redisService.removeSetElt(keys,e);
            });
        }
        return new Result<>();
    }
    /**
     * 携程房根据效应价格房态，如果产品对应没有价格房态缓存，默认认为失效
     * 辅助
     */
    @SneakyThrows
    @Override
    public Result<Object> dealRoomFailure() {
        String keys="switch_hotel_room_is_down";
        Set<Object> set=redisService.getMembers(keys);
        if(!CollectionUtils.isEmpty(set)){
            Object object=set.stream().findFirst().orElse(null);
            log.info("==========object的值为{}======",object);
            String[] s=object.toString().split("_");
            Integer hotelId= Integer.valueOf(s[0]);
            Integer roomId= Integer.valueOf(s[1]);
            SwitchCreateRoomEntity switchCreateRoomEntity=switchCreateRoomMapper.selectByHotelIdAndRoomId(hotelId,roomId);
            if(ObjectUtils.isEmpty(switchCreateRoomEntity)){
                SetRoomOnlineOfflineVo setRoomOnlineOfflineVo=new SetRoomOnlineOfflineVo();
                setRoomOnlineOfflineVo.setRoomTypeId(roomId);
                setRoomOnlineOfflineVo.setHotelId(hotelId);
                setRoomOnlineOfflineVo.setChannel("Ctrip");
                setRoomOnlineOfflineVo.setRoomStatus(1);
                Result<Object> result=switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                log.info("=======result的结果为{}======",result);
                if(result.getMsg().toString().contains("频繁")||result.getMsg().toString().contains("签名")){
                    Thread.sleep(6000);
                    result=switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                    log.info("=======第二次调用接口下线产品result的结果为{}======",result);
                }
            }else{
                Date now=new Date();
                Date date=switchCreateRoomEntity.getCreateTime();
                long diff=now.getTime()-date.getTime();
                long nd = 1000 * 24 * 60 * 60;
                long nh = 1000 * 60 * 60;
                long nm = 1000 * 60;
                long hour = diff % nd / nh;
                //如果是半小时的还没有价格房态数据，统一默认为失效
                if(hour>0){
                    SetRoomOnlineOfflineVo setRoomOnlineOfflineVo=new SetRoomOnlineOfflineVo();
                    setRoomOnlineOfflineVo.setRoomTypeId(roomId);
                    setRoomOnlineOfflineVo.setHotelId(hotelId);
                    setRoomOnlineOfflineVo.setChannel("Ctrip");
                    setRoomOnlineOfflineVo.setRoomStatus(0);
                    Result<Object> result=switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                    log.info("=======result的结果为{}======",result);
                    if(result.getMsg().toString().contains("频繁")||result.getMsg().toString().contains("签名")){
                        Thread.sleep(6000);
                        result=switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                        log.info("=======第二次调用接口下线产品result的结果为{}======",result);
                        if(result.getCode()==CommonConstants.SUCCESS){
                            productFailureDealData(switchCreateRoomEntity);
                        }
                    }else{
                        productFailureDealData(switchCreateRoomEntity);
                    }
                }
            }
            redisService.removeSetElt(keys,object);
        }
        return new Result<>();
    }


    /**
     * 产品失效 删除相关数据合缓存
     */
    public void productFailureDealData(SwitchCreateRoomEntity switchCreateRoomEntity){
        //2.添加到产品失效库
        SwitchCreateRoomFailureEntity switchCreateRoomFailureEntity=new SwitchCreateRoomFailureEntity();
        BeanUtils.copyProperties(switchCreateRoomEntity,switchCreateRoomFailureEntity);
        switchCreateRoomFailureEntity.setId(switchCreateRoomFailureEntity.getId()+StringUtil.getFourRandom());
        switchCreateRoomFailureEntity.setModifyTime(new Date());
        int flag=switchCreateRoomFailureMapper.insert(switchCreateRoomFailureEntity);
        //3.从产品库删除
        if(flag>0){
            switchCreateRoomMapper.deleteRoomInfoByMtHotelIdAndMtHotelRoomIdAndMtGoodId(switchCreateRoomEntity.getMtHotelId(), Integer.valueOf(switchCreateRoomEntity.getMtRoomId()),switchCreateRoomEntity.getMtGoodId());
            //删除 key :美团酒店ID+美团产品ID
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            redisService.hmDel(CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId());
            if(redisService.exists(key)){
                redisService.remove(key);
            }
            String key2=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_1";
            if(redisService.exists(key2)){
                redisService.remove(key2);
            }
            redisService.hmDel(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId());
            key2=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_0";
            if(redisService.exists(key2)){
                redisService.remove(key2);
            }
            String ke=CommonConstants.SWITCH_SELLING_REDIS_BY_MT+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId();
            redisService.hmDel(CommonConstants.SWITCH_SELLING_REDIS_BY_MT,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId());
            if(redisService.exists(ke)){
                redisService.remove(ke);
            }
            //清除取消规则
            ke=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_0";
            if(redisService.exists(ke)){
                redisService.remove(ke);
            }
            ke=CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId()+"_1";
            if(redisService.exists(ke)){
                redisService.remove(ke);
            }
            redisService.hmDel(CommonConstants.SWITCH_CREATE_ROOM_CANCEL_RULE,switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId());
        }
        //5.更新创建子物理房型
        switchCreateBasicRoomService.updateCreateStateByBasicRoomId(switchCreateRoomEntity.getBasicRoomTypeId());
    }
    /**
     * 针对第三公式的酒店进行调价，根据代理通的商机数据 轮出率为0的进行降价处理
     */
    @Override
    public Result<Object> adjustHotelFormulaByOutputIsZero(MultipartFile excelFile) {
        if(redisService.exists("is_clear_adjust_hotel_data")){
            redisService.remove(CommonConstants.SWITCH_ADJUST_HOTEL_RATE_BY_OUT_PUT_IS_ZERO);
            switchHotelUpMapper.truncateTable();
        }
        List<SwitchHotelOutPutEntity> switchHotelOutPutEntities = new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            tab:
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                SwitchHotelOutPutEntity switchHotelOutPutEntity=new SwitchHotelOutPutEntity();
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(0);
                cell.setCellType(CellType.STRING);
                switchHotelOutPutEntity.setMasterHotelId(Integer.valueOf(cell.getStringCellValue()));
                cell = sheetRow.getCell(1);
                Double hotelId=cell.getNumericCellValue();
                switchHotelOutPutEntity.setHotelId(hotelId.intValue());
                cell.setCellType(CellType.STRING);
                cell = sheetRow.getCell(5);
                String sale=cell.getStringCellValue();
                if(sale.equals("不可售")){
                    continue tab;
                }
                switchHotelOutPutEntity.setSale(sale);
                cell.setCellType(CellType.STRING);
                cell = sheetRow.getCell(6);
                Double total=cell.getNumericCellValue();
                switchHotelOutPutEntity.setTotal(total.intValue());
                cell.setCellType(CellType.STRING);
                cell = sheetRow.getCell(8);
                Double rate=cell.getNumericCellValue();
                switchHotelOutPutEntity.setOutput(rate*100);
                Example example=new Example(SwitchHotelOutPutEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("hotelId",switchHotelOutPutEntity.getHotelId());
                int count=switchHotelOutPutMapper.selectCountByExample(example);
                if(count<1){
                    switchHotelOutPutEntities.add(switchHotelOutPutEntity);
                }
            }
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        if(switchHotelOutPutEntities.size()>0){
            switchHotelOutPutMapper.insertList(switchHotelOutPutEntities);
        }
        //异步找出数据,并放入缓存
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(new asyncAdjustPirceThread());
        executorService.shutdown();
        return new Result<>();
    }
    /**
     * 异步处理数据
     */
    class asyncAdjustPirceThread implements Runnable{

        @Override
        public void run() {
            List<Integer> hotelId=switchHotelUpMapper.selectOutPutIsZeroHotelList();
            Integer rate=2;
            if(redisService.exists("switch_adjust_hotel_rate")){
                rate= (Integer) redisService.get("switch_adjust_hotel_rate");
            }
            String key=CommonConstants.SWITCH_ADJUST_HOTEL_RATE_BY_OUT_PUT_IS_ZERO;
            Integer finalRate = rate;
            hotelId.forEach(e->{
                redisService.hmSet(key,e, finalRate);
            });

        }
    }
    /**
     * 匹配携程-美团上架的酒店房型相关信息：价格、房态、早餐信息
     */
    @Override
    public Result<Object> compareHotelRoomInfoByApi(CompareHotelRoomVo compareHotelRoomVo) {
        //判断vo是否为空
        if(ObjectUtils.isEmpty(compareHotelRoomVo.getHotelId())){
            return new Result<>(CommonConstants.SUCCESS);
        }
        //获取携程子酒店id
        Integer swHotelId = compareHotelRoomVo.getHotelId();
        List<Map<String,Object>> returnList = new ArrayList<>();
        //携程相关参数
        Map swMap = new HashMap();
        //美团相关参数
        Map mtMap = new HashMap();
        //根据携程子酒店id，获取母酒店id
        Example example = new Example(SwitchCreateRoomEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("hotelId",swHotelId);
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByExample(example);
        List<Integer> switchRoomIds = new ArrayList<>();
        List<Long> mtHotelIds = new ArrayList<>();
        if(!switchCreateRoomEntities.isEmpty() && switchCreateRoomEntities.size()>0){
            for(int i=0;i<switchCreateRoomEntities.size();i++){
                SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomEntities.get(i);
                switchRoomIds.add(switchCreateRoomEntity.getRoomId());
                if(!ObjectUtils.isEmpty(switchCreateRoomEntity.getMtHotelId()) && mtHotelIds.size() ==0){
                    mtHotelIds.add(Long.valueOf(switchCreateRoomEntity.getMtHotelId()));
                }
            }
        }else{
            return null;
        }
        //调用携程查询房型相关接口
        Calendar calendar = Calendar.getInstance();
        String nowDate = DateUtil.getToday2();
        try {
            calendar.setTime(new SimpleDateFormat("yyyyMMdd").parse(nowDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String startDate = "/Date("+calendar.getTimeInMillis()+"+0800)/";
        calendar.add(Calendar.DAY_OF_MONTH,1);//加1天
        String endDate = "/Date("+calendar.getTimeInMillis()+"+0800)/";
        swMap.put("channel","Ctrip");
        swMap.put("isGetPurchasePrice",false);
        swMap.put("hotelId",swHotelId);
        swMap.put("roomIds",switchRoomIds);
        swMap.put("startDate",startDate);
        swMap.put("endDate",endDate);
        String gateUrl=CommonUrlConstants.GATE_WAY_HOST_SEC;
        String swUrl = gateUrl+"/api/switchsonline"+ "/switchRoomPrice/GetRoomPriceDirect";
        Result<Object> swObjectResult = RestTemplateUtils.post(swUrl, JacksonUtil.objectToJson(swMap),restTemplate);
        log.info("swObjectResult>>>>{}",JacksonUtil.objectToJson(swObjectResult));
        if(ObjectUtils.isEmpty(swObjectResult) || ObjectUtils.isEmpty(swObjectResult.getData())){
            return new Result<>(CommonEnums.DATA_NULL.getCode(),"调用携程获取房价接口，返回酒店数据为空！");
        }
        String swStatusUrl = gateUrl+"/api/switchsonline"+ "/switchRoomPrice/GetRoomStatusDirect";
        Result<Object> swStatusObjectResult = RestTemplateUtils.post(swStatusUrl, JacksonUtil.objectToJson(swMap),restTemplate);
        log.info("swStatusObjectResult>>>>{}",JacksonUtil.objectToJson(swStatusObjectResult));
        if(ObjectUtils.isEmpty(swStatusObjectResult) || ObjectUtils.isEmpty(swStatusObjectResult.getData())){
            return new Result<>(CommonEnums.DATA_NULL.getCode(),"调用携程获取房态接口，返回酒店数据为空！");
        }
        //调用美团查询酒店房型相关接口
        String checkinDate = DateUtil.getToday();
        String checkoutDate = DateUtil.getUpDate(checkinDate,-1);
        MtHotelGoodsParamVo mtHotelGoodsParamVo = new MtHotelGoodsParamVo();

        mtHotelGoodsParamVo.setHotelIds(mtHotelIds);
        mtHotelGoodsParamVo.setCheckinDate(checkinDate);
        mtHotelGoodsParamVo.setCheckoutDate(checkoutDate);
        mtHotelGoodsParamVo.setGoodsType(1);
        String mtUrl = gateUrl+"/api/meituan"+"/mtHotelGoods/getMtHotelGoods";
        Result<MtHotelGoodsVo> mtObjectResult = RestTemplateUtils.post(mtUrl, JacksonUtil.objectToJson(mtHotelGoodsParamVo),restTemplate);
        log.info("mtObjectResult>>{}",JacksonUtil.objectToJson(mtObjectResult));

        if(ObjectUtils.isEmpty(mtObjectResult) || ObjectUtils.isEmpty(mtObjectResult.getData())){
            return new Result<>(CommonEnums.DATA_NULL.getCode(),"调用美团接口，返回酒店数据为空！");
        }

        Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = switchPushRoomService.getOnlinePriceSet();
        if(redisService.exists(CommonConstants.SWITCH_IS_OPEN_HOTEL_OWNER_PRICE_FORMULA)){
            //获取酒店是否有自已独立的价格公式
            priceSetMap=getOnlinePriceSetByData(swHotelId,priceSetMap);
        }
        Integer rates= (Integer) redisService.hmGet(CommonConstants.SWITCH_ADJUST_HOTEL_RATE_BY_OUT_PUT_IS_ZERO,swHotelId);
        if(!ObjectUtils.isEmpty(rates)){
            priceSetMap.entrySet().forEach(e->{
                List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntities= e.getValue();
                for(SwitchPriceBaseSetEntity switchPriceBaseSetEntity:switchPriceBaseSetEntities){
                    //最低只能到10
                    if(switchPriceBaseSetEntity.getRate().doubleValue()>10){
                        switchPriceBaseSetEntity.setRate(BigDecimal.valueOf(switchPriceBaseSetEntity.getRate().doubleValue()-rates.doubleValue()));
                    }
                }
                e.setValue(switchPriceBaseSetEntities);
            });
        }
        //获取价格比例
        List<SwitchPriceBaseSetEntity> switchPriceBaseSetEntityByCtripChannel=priceSetMap.get(SwitchChannelNameEnums.CTRIP.getName());
        Integer addPrice=(Integer) redisService.hmGet(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER,mtHotelIds.get(0));
        Double addRate= (Double) redisService.hmGet(CommonConstants.SWITCH_HOTEL_ACTIVE_LIST_BY_OPEN_ACTIVE,mtHotelIds.get(0));
        if(ObjectUtils.isEmpty(addRate)){
            addRate=1.0;
        }
        double addPrices=0.00;
        if(!ObjectUtils.isEmpty(addPrice)){
            addPrices=addPrice.doubleValue()/100;
        }
        //是否推送消息 true :推送； false :不推送
        boolean isMsg = false;

        for(int i=0;i<switchCreateRoomEntities.size();i++){
            Map<String,Object> returnMap = new HashMap<>();
            boolean isCompare = false;
            BigDecimal swPriPre = new BigDecimal(1);
            SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomEntities.get(i);
            Map<String,Object> swTempMap = getSwRoomInfoByReturn(switchCreateRoomEntity.getRoomId(),swObjectResult,swStatusObjectResult);
            if(ObjectUtils.isEmpty(swTempMap) && swTempMap.size() == 0){
                continue;
            }
            returnMap.putAll(swTempMap);
            Map<String,Object> mtTempMap = getMtGoodsINfoByReturn(switchCreateRoomEntity.getMtGoodId(),mtObjectResult);
            if(ObjectUtils.isEmpty(mtTempMap) && mtTempMap.size() == 0){
                continue;
            }
            returnMap.putAll(mtTempMap);
            returnMap.put("hotelId",switchCreateRoomEntity.getHotelId());
            returnMap.put("roomName",switchCreateRoomEntity.getRoomName());
            returnMap.put("mtHotelId",switchCreateRoomEntity.getMtHotelId());

            returnMap.put("switchRoomName",switchCreateRoomEntity.getSwitchRoomName());
            returnMap.put("mtRoomName",switchCreateRoomEntity.getMtRoomName());

            //使用的价格阶梯比例
            BigDecimal rate = new BigDecimal(1);
            BigDecimal swPrice = new BigDecimal(swTempMap.get("price").toString());
            //校验价格是否相等
            if(switchPriceBaseSetEntityByCtripChannel.size()>0){
                //获取价格阶梯比例
                for(int j=0;j<switchPriceBaseSetEntityByCtripChannel.size();j++) {
                    Map<String,Object> switchPriceBaseSetEntityByCtripChannelMap = JacksonUtil.parse(JacksonUtil.objectToJson(switchPriceBaseSetEntityByCtripChannel.get(j)),Map.class);
                    BigDecimal minPri = new BigDecimal(0);
                    BigDecimal maxPri = new BigDecimal(0);
                    if(!switchPriceBaseSetEntityByCtripChannelMap.isEmpty() && switchPriceBaseSetEntityByCtripChannelMap.size()>0){
                        minPri = new BigDecimal(switchPriceBaseSetEntityByCtripChannelMap.get("minPrice").toString());
                        maxPri = new BigDecimal(switchPriceBaseSetEntityByCtripChannelMap.get("maxPrice").toString());
                        rate = new BigDecimal(switchPriceBaseSetEntityByCtripChannelMap.get("rate").toString()).add(new BigDecimal(100)).divide(new BigDecimal(100),2, RoundingMode.HALF_UP);
                        //判断价格是否在此区间
                        if(swPrice.compareTo(minPri) > 0 && swPrice.compareTo(maxPri) <= 0){
                            break;
                        }

                    }

                }
            }
            if(!ObjectUtils.isEmpty(mtTempMap.get("mtPrice"))){
                BigDecimal mtBd = new BigDecimal(mtTempMap.get("mtPrice").toString()).multiply(rate).setScale(2,BigDecimal.ROUND_HALF_UP);
                swPrice.add(BigDecimal.valueOf(addPrices));
                swPrice.divide(BigDecimal.valueOf(addRate));
                log.info("mtBd.toPlainString()>>>{}",mtBd.toPlainString());
                returnMap.put("mtComparePrice",mtBd);
                if(mtBd.compareTo(swPrice) == 0){
                    //校验早餐数量是否一样
                    if(swTempMap.get("breakfast").equals(mtTempMap.get("mtBreakfastNum").toString())){
                        if(swTempMap.get("saleStatus").toString().equals(mtTempMap.get("mtGoodsStatus").toString())) {
                            isCompare = true;
                        }
                    }
                }
            }
            //当存在异常的酒店房型信息，推送钉钉消息
            if(!isCompare){
                isMsg = true;
            }
            returnMap.put("isCompare",isCompare);
            returnList.add(returnMap);
        }
        //推送钉钉消息
        if(isMsg){
            try {
                SendUtils.dingMsg("【房型比对-异常产品信息】", "携程酒店id:【" + swHotelId + "】及时关注！！！ ", MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(), restTemplate);
            }catch (Exception e){
                log.info("后台房型比对钉钉推送异常！");
            }
        }
        return new Result<>(returnList);
    }

    /**
     * 查询携程当天房型相关信息
     * @param swObjectResult 价格
     * @param swStatusObjectResult 房态
     * @return
     */
    public Map<String,Object> getSwRoomInfoByReturn(Integer roomId,Result<Object> swObjectResult,Result<Object> swStatusObjectResult){
        Map<String,Object> swReturn = new HashMap<>();
        Map<String,Object> swPricesReturn = new HashMap<>();
        Map<String,Object> swStatusReturn = new HashMap<>();
        if(!ObjectUtils.isEmpty(roomId) && !ObjectUtils.isEmpty(swObjectResult) && !ObjectUtils.isEmpty(swStatusObjectResult)){
            //对结构进行格式化
            Map<String,Object> getData = JacksonUtil.parse(JacksonUtil.objectToJson(swObjectResult.getData()),Map.class);
            List<Map<String,Object>>  channelRoomPricesList = JacksonUtil.parse(JacksonUtil.objectToJson(getData.get("channelRoomPrices")),List.class);
            if(ObjectUtils.isEmpty(channelRoomPricesList)||channelRoomPricesList.size()<0){
                return swReturn;
            }
            Map<String,Object> swChannelRoomPrices = JacksonUtil.parse(JacksonUtil.objectToJson(channelRoomPricesList.get(0)),Map.class);
            if(!ObjectUtils.isEmpty(swChannelRoomPrices)){
                //获取携程对应相关售卖房型信息
                List<Map<String,Object>> swRoomPricesList = JacksonUtil.parse(JacksonUtil.objectToJson(swChannelRoomPrices.get("roomPrices")),List.class);
                if(swRoomPricesList.size()>0){
                    a:for(int l=0;l<swRoomPricesList.size();l++){
                        Map<String,Object> roomPricesMap = swRoomPricesList.get(l);
                        if(roomPricesMap.size()>0){
                            for(Map.Entry<String, Object> entry : roomPricesMap.entrySet()){
                                String mapKey = entry.getKey();
                                Object mapValue = entry.getValue();
                                if("roomId".equals(mapKey) ){
                                    BigDecimal db = new BigDecimal(mapValue.toString());
                                    if(db.compareTo(new BigDecimal(roomId)) == 0) {
                                        swPricesReturn = roomPricesMap;
                                        break a;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //对房态结构进行格式化
            List<Map<String,Object>> swChannelRoomStatusList = JacksonUtil.parse(JacksonUtil.objectToJson(swStatusObjectResult.getData()),List.class);
            if(!ObjectUtils.isEmpty(swChannelRoomStatusList) && swChannelRoomStatusList.size()>0){
                a:for(int l=0;l<swChannelRoomStatusList.size();l++){
                    Map<String,Object> roomStatusMap = swChannelRoomStatusList.get(l);
                    if(roomStatusMap.size()>0){
                        for(Map.Entry<String, Object> entry : roomStatusMap.entrySet()){
                            String mapKey = entry.getKey();
                            Object mapValue = entry.getValue();
                            if("roomId".equals(mapKey) ){
                                BigDecimal db = new BigDecimal(mapValue.toString());
                                if(db.compareTo(new BigDecimal(roomId)) == 0) {
                                    swStatusReturn = roomStatusMap;
                                    break a;
                                }
                            }
                        }
                    }
                }
            }
        }
        if(swPricesReturn.size()>0 && swStatusReturn.size()>0){
            for(Map.Entry<String, Object> entry : swPricesReturn.entrySet()){
                String mapKey = entry.getKey();
                Object mapValue = entry.getValue();
                if("roomId".equals(mapKey) || "price".equals(mapKey) || "breakfast".equals(mapKey)){
                    if("roomId".equals(mapKey) ){
                        BigDecimal db = new BigDecimal(mapValue.toString());
                        mapValue = db.toPlainString();
                    }
                    if("breakfast".equals(mapKey)){
                        if(new BigDecimal(String.valueOf(mapValue)).compareTo(new BigDecimal(0)) == 0){
                            mapValue = "无早";
                        }else if(new BigDecimal(String.valueOf(mapValue)).compareTo(new BigDecimal(1)) == 0){
                            mapValue = "单早";
                        }else if(new BigDecimal(String.valueOf(mapValue)).compareTo(new BigDecimal(2)) == 0){
                            mapValue = "双早";
                        }else{
                            mapValue= new BigDecimal(mapValue.toString()).toPlainString()+ "早";
                        }
                    }
                    swReturn.put(mapKey,mapValue);
                }
            }
            for(Map.Entry<String, Object> entry : swStatusReturn.entrySet()){
                String mapKey = entry.getKey();
                Object mapValue = entry.getValue();
                if("saleStatus".equals(mapKey)){
                    //房态:0满房1销售2限量
                    if(new BigDecimal(mapValue.toString()).compareTo(new BigDecimal(0)) == 0){
                        swReturn.put(mapKey,"满房");
                    }else{
                        swReturn.put(mapKey,"有房");
                    }
                }
            }
        }
        log.debug("swReturn>>{}",JacksonUtil.objectToJson(swReturn));
        return swReturn;
    }
    /**
     * 根据产品id 获取对应产品相关信息
     * @param goodsId
     * @param mtObjectResult
     * @return
     */
    public Map<String,Object> getMtGoodsINfoByReturn(Integer goodsId,Result<MtHotelGoodsVo> mtObjectResult){
        Map<String,Object> mtResultMap = new HashMap<>();
        Map<String,Object> mtGoodsMap = new HashMap<>();
        Map<String,Object> getData = JacksonUtil.parse(JacksonUtil.objectToJson(mtObjectResult.getData()),Map.class);
        if(!ObjectUtils.isEmpty(goodsId) && !ObjectUtils.isEmpty(mtObjectResult)){
            List hotelGoods = (List) getData.get("hotelGoods");
            Map<String,Object> hotelGoodsMap = JacksonUtil.parse(JacksonUtil.objectToJson(hotelGoods.get(0)),Map.class);
            List goods = JacksonUtil.parse(JacksonUtil.objectToJson(hotelGoodsMap.get("goods")),List.class);
            if(!ObjectUtils.isEmpty(goods) && goods.size()>0){
                a:for(int l=0;l<goods.size();l++){
                    Map<String,Object> goodsMap = JacksonUtil.parse(JacksonUtil.objectToJson(goods.get(l)),Map.class);
                    if(goodsMap.size()>0){
                        for(Map.Entry<String, Object> entry : goodsMap.entrySet()){
                            String mapKey = entry.getKey();
                            Object mapValue = entry.getValue();
//                            System.out.println(mapKey+":"+mapValue);
                            if("goodsId".equals(mapKey) ){
                                BigDecimal db = new BigDecimal(mapValue.toString());
                                log.info("goodsId>>>>>>>{}---mapValue>>>{}",goodsId,mapValue.toString());
                                if(db.compareTo(new BigDecimal(goodsId)) == 0) {
                                    mtGoodsMap = goodsMap;
                                    break a;
                                }
                            }
                        }
                    }
                }
            }
        }
        if(!ObjectUtils.isEmpty(mtGoodsMap) && mtGoodsMap.size()>0){
            mtResultMap.put("mtGoodsId",mtGoodsMap.get("goodsId"));
            mtResultMap.put("mtGoodsName",mtGoodsMap.get("goodsName"));
            if(new BigDecimal(mtGoodsMap.get("goodsStatus").toString()).compareTo(new BigDecimal(1)) == 0){
                mtResultMap.put("mtGoodsStatus","有房");
            }else{
                mtResultMap.put("mtGoodsStatus","满房");
            }
            List breakFast = JacksonUtil.parse(JacksonUtil.objectToJson(mtGoodsMap.get("breakFast")),List.class);
            if(breakFast.size()>0){
                Map<String,Object> mtHotelGoodsBreakfastMap = JacksonUtil.parse(JacksonUtil.objectToJson(breakFast.get(0)),Map.class);
                if(new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastType").toString()).compareTo(new BigDecimal(1)) == 0){
                    if(new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastNum").toString()).compareTo(new BigDecimal(1)) == 0){
                        mtResultMap.put("mtBreakfastNum","单早");
                    }else if(new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastNum").toString()).compareTo(new BigDecimal(2)) == 0){
                        mtResultMap.put("mtBreakfastNum","双早");
                    }else{
                        mtResultMap.put("mtBreakfastNum",new BigDecimal(mtHotelGoodsBreakfastMap.get("breakfastNum").toString()).toPlainString()+"早");
                    }
                }else {
                    mtResultMap.put("mtBreakfastNum","无早");
                }
            }
            List priceModels = JacksonUtil.parse(JacksonUtil.objectToJson(mtGoodsMap.get("priceModels")),List.class);
            if(priceModels.size()>0){
                Map<String,Object> priceModelsMap = JacksonUtil.parse(JacksonUtil.objectToJson(priceModels.get(0)),Map.class);
                double mtPriceDb = Double.valueOf(priceModelsMap.get("salePrice").toString()) - Double.valueOf(priceModelsMap.get("subPrice").toString());
                BigDecimal bg = new BigDecimal(mtPriceDb);
                double mtPrice = bg.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP).doubleValue();
                mtResultMap.put("mtPrice", mtPrice);
            }
        }
        return mtResultMap;
    }
    /**
     * 新增活动类型
     * @param switchHotelActiveGenreEntity
     * @return
     */
    @Override
    public Result<Object> addActive(SwitchHotelActiveGenreEntity switchHotelActiveGenreEntity) {
        Example example=new Example(SwitchHotelActiveGenreEntity.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("genre",switchHotelActiveGenreEntity.getGenre());
        int count=switchHotelActiveGenreMapper.selectCountByExample(example);
        if(count>0){
            return new Result<>();
        }
        int flag= switchHotelActiveGenreMapper.insert(switchHotelActiveGenreEntity);
        if(flag>0){
            return new Result<>();
        }else{
            return new Result<>("添加失败");
        }
    }
    /**
     * 开启促销活动
     * @param excelFile
     * @param genreId
     * @return
     */
    @Override
    public Result<Object> openActive(MultipartFile excelFile, Integer genreId) {
        Example example=new Example(SwitchHotelActiveGenreEntity.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("id",genreId);
        SwitchHotelActiveGenreEntity switchHotelActiveGenreEntity=switchHotelActiveGenreMapper.selectOneByExample(example);
        List<SwitchHotelActiveListEntity> switchHotelActiveListEntities = new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            tab:
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                SwitchHotelActiveListEntity switchHotelActiveListEntity=new SwitchHotelActiveListEntity();
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(0);
                cell.setCellType(CellType.STRING);
                Integer hotelId= Integer.valueOf(cell.getStringCellValue());
                switchHotelActiveListEntity.setHotelId(hotelId);
                switchHotelActiveListEntity.setGenreId(genreId);
                switchHotelActiveListEntity.setCreateTime(new Date());
                switchHotelActiveListEntities.add(switchHotelActiveListEntity);
            }
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        if(switchHotelActiveListEntities.size()>0){
            switchHotelActiveListMapper.insertList(switchHotelActiveListEntities);
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            executorService.submit(new asyncOpenActiveThread(switchHotelActiveGenreEntity,switchHotelActiveListEntities));
            executorService.shutdown();
        }
        return null;
    }

    /**
     * 异步处理缓存数据
     */
    class asyncOpenActiveThread implements Runnable {
        private SwitchHotelActiveGenreEntity switchHotelActiveGenreEntity;
        private  List<SwitchHotelActiveListEntity> switchHotelActiveListEntities;

        public asyncOpenActiveThread(SwitchHotelActiveGenreEntity switchHotelActiveGenreEntity, List<SwitchHotelActiveListEntity> switchHotelActiveListEntities) {
            this.switchHotelActiveGenreEntity = switchHotelActiveGenreEntity;
            this.switchHotelActiveListEntities = switchHotelActiveListEntities;
        }

        @Override
        public void run() {
            String keys="switch_hotel_list_by_open_active";
            switchHotelActiveListEntities.forEach(e->{
                redisService.hmSet(keys,e.getHotelId(),switchHotelActiveGenreEntity.getRate());
            });
        }
    }

    /**
     * 获取活动数据列表
     */
    @Override
    public Result<Object> getActiveList() {
        List<SwitchHotelActiveGenreEntity> switchHotelActiveGenreEntities= switchHotelActiveGenreMapper.selectAll();
        return new Result<>(switchHotelActiveGenreEntities);
    }

    /**
     * 针对优势酒店->普通酒店 后面天数进行关房
     * @return
     */
    @Override
    public Result<Object> switchVipToNormalCloseStatus() {
        //如果是vip->普通酒店，需要把后面几天的房态关掉
        String keyss="switch_vip_to_normal";
        Set<Object> set=redisService.members(keyss);
        set.forEach(e->{
            Integer hotelId=switchCreateRoomMapper.selectHotelIdByMtHotelId(e.toString());
            if(!ObjectUtils.isEmpty(hotelId)){
                String switch_create_room_key="switchCreateRoomKey";
                String switchCreateRoomKey=switch_create_room_key+hotelId;
                List<SwitchCreateRoomEntity> switchCreateRoomEntities;
                if(!redisService.exists(switchCreateRoomKey)){
                    switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(hotelId);
                    Random r = new Random(1);
                    redisService.set(switchCreateRoomKey,JacksonUtil.objectToJson(switchCreateRoomEntities), (long) r.nextInt(1000));
                }else{
                    String str= (String) redisService.get(switchCreateRoomKey);
                    switchCreateRoomEntities=JacksonUtil.jsonToList(str,SwitchCreateRoomEntity.class);
                }
                if(!ObjectUtils.isEmpty(switchCreateRoomEntities)&&switchCreateRoomEntities.size()>0){
                    BatchPushRoomVo batchPushRoomVo=new BatchPushRoomVo();
                    batchPushRoomVo.setHotelId(hotelId);
                    List<RoomDataEntityVo> roomDataEntitys=new ArrayList<>();
                    switchCreateRoomEntities.forEach(e1->{
                        RoomStatusModelVo roomStatusModelVo;
                        int vipDay=getDaysCommonBaseSetForVip();
                        int normalDay=getDaysCommonBaseSetForNormal();
                        String endTimes=DateUtil.getDate(vipDay);
                        String statrTimes=DateUtil.getDate(normalDay);
                        RoomDataEntityVo roomDataEntityVo1=new RoomDataEntityVo();
                        roomDataEntityVo1.setRoomId(e1.getRoomId());
                        roomDataEntityVo1.setEndDate(endTimes);
                        roomDataEntityVo1.setStartDate(statrTimes);
                        roomStatusModelVo=new RoomStatusModelVo();
                        roomStatusModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                        roomStatusModelVo.setSaleStatus(0);
                        roomDataEntityVo1.setRoomStatusModel(roomStatusModelVo);
                        roomDataEntitys.add(roomDataEntityVo1);
                    });
                    batchPushRoomVo.setRoomDataEntitys(roomDataEntitys);
                    log.info("========优势酒店->普通酒店调用携程的请求参数为{}", JSONUtil.toJsonStr(batchPushRoomVo));
                    Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                    log.info("=====优势酒店->普通酒店调用携程进行关房，返回的msg为{}返回的数据为{}=====",result.getMsg(),JSONUtils.toJSONString(result.getData()));
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
            }
        });
        return new Result<>();
    }
    /**
     * 导出有订单的酒店数据
     * @return
     */
    @Override
    public XSSFWorkbook exportOrderHotel() {
        List<Integer> hotelIds=switchHotelUpMapper.exportOrderHotel();
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("uphotel");//创建一张表
        Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("酒店");//第一列
        titleRow.createCell(1).setCellValue("酒店ID");
        int cell=1;
        for(Integer hotelId:hotelIds){
            Row row = sheet.createRow(cell);//从第二行开始保存数据
            row.createCell(0).setCellValue("");
            row.createCell(1).setCellValue(hotelId);//将数据库的数据遍历出来
            cell++;
        }
        return wb;
    }
    /**
     * 获取天天特价的酒店数据
     * @param num
     * @return
     */
    @Override
    public XSSFWorkbook exportActiveHotel(Integer num) {
        List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchHotelUpMapper.exportActiveHotel(num);
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("uphotel");//创建一张表
        Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("hotel_id");//第一列
        titleRow.createCell(1).setCellValue("mt_hotel_id");
        int cell=1;
        for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
            Row row = sheet.createRow(cell);//从第二行开始保存数据
            row.createCell(0).setCellValue(switchCreateRoomEntity.getHotelId());
            row.createCell(1).setCellValue(switchCreateRoomEntity.getMtHotelId());//将数据库的数据遍历出来
            cell++;
        }
        return wb;
    }
    /**
     * 获取售卖酒店的房型Id
     * @return
     */
    @Override
    public Result<Object> getSaleHotelRoomCanceleRule() {
        if(redisService.exists("is_get_sale_hotel_room_cancele_rule")){
            return new Result<>();
        }
        redisService.set("is_get_sale_hotel_room_cancele_rule",1);
        //获取上架的酒店
        String key="Switch_hotel_room_sale_list";
        if(!redisService.exists(key)||redisService.listSize(key)<1){
            List<Integer> switchHotelUpEntities=switchHotelUpMapper.selectSaleHotelList();
            if(ObjectUtils.isEmpty(switchHotelUpEntities)||switchHotelUpEntities.size()<1){
                return new Result<>();
            }
            switchHotelUpEntities.forEach(e->{
                redisService.lPush(key,e);
            });
        }
        Integer hotelId= (Integer) redisService.lPop(key);
        List<Integer> roomTypeList=switchCreateRoomMapper.selectRoomTypeList(hotelId);
        if(ObjectUtils.isEmpty(roomTypeList)||roomTypeList.size()<1){
            redisService.remove("is_get_sale_hotel_room_cancele_rule");
            return new Result<>();
        }
        Map<String, Object> map=new HashMap<>();
        map.put("channel","Ctrip");
        map.put("hotelId",hotelId);
        map.put("roomTypeList",roomTypeList);
        map.put("startDate",DateUtil.getNextDays(0));
        map.put("endDate",DateUtil.getNextDays(0));
        Result<List<RoomSaleRuleVo>> result= switchBasicRoomTypeService.getSaleRuleDirect(map);
        List<RoomSaleRuleVo> roomSaleRuleVos=result.getData();
        if(!ObjectUtils.isEmpty(roomSaleRuleVos)){
            roomSaleRuleVos.forEach(e->{
                Example example=new Example(SwitchHotelRoomSaleEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("hotelId",e.getHotelId());
                criteria.andEqualTo("roomId",e.getRoomId());
                int count=switchHotelRoomSaleMapper.selectCountByExample(example);
                if(count<1){
                    CtripSellRuleVo ctripSellRuleVo=e.getCtripSellRule();
                    List<CancelDetailsVo> cancelDetails=ctripSellRuleVo.getCancelDetails();
                    cancelDetails.forEach(e1->{
                        SwitchHotelRoomSaleEntity switchHotelRoomSaleEntity=new SwitchHotelRoomSaleEntity();
                        switchHotelRoomSaleEntity.setHotelId(e.getHotelId());
                        switchHotelRoomSaleEntity.setRoomId(e.getRoomId());
                        int days=(e1.getLatestCancelTime()/24);
                        switchHotelRoomSaleEntity.setDays(days);
                        switchHotelRoomSaleEntity.setHours(String.valueOf(24-e1.getLatestCancelTime()%24));
                        switchHotelRoomSaleMapper.insert(switchHotelRoomSaleEntity);
                    });
                }else{
                    CtripSellRuleVo ctripSellRuleVo=e.getCtripSellRule();
                    List<CancelDetailsVo> cancelDetails=ctripSellRuleVo.getCancelDetails();
                    cancelDetails.forEach(e1->{
                        SwitchHotelRoomSaleEntity switchHotelRoomSaleEntity=new SwitchHotelRoomSaleEntity();
                        switchHotelRoomSaleEntity.setHotelId(e.getHotelId());
                        switchHotelRoomSaleEntity.setRoomId(e.getRoomId());
                        int days=(e1.getLatestCancelTime()/24);
                        switchHotelRoomSaleEntity.setDays(days);
                        switchHotelRoomSaleEntity.setHours(String.valueOf(24-e1.getLatestCancelTime()%24));
                        switchHotelRoomSaleMapper.updateByExampleSelective(switchHotelRoomSaleEntity,example);
                    });
                }
            });
        }
        redisService.remove("is_get_sale_hotel_room_cancele_rule");
        return new Result<>(roomTypeList);
    }

    /**
     * 导入天天特价酒店数据入表和缓存
     * @param excelFile
     */
    @SneakyThrows
    @Override
    public void openActiveHotel(MultipartFile excelFile) {
        Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
        excelFile.getInputStream().close();
        //工作表对象
        Sheet sheet = workbook.getSheetAt(0);
        List<SwitchJoinActiveHotelEntity> switchJoinActiveHotelEntities=new ArrayList<>();
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            Row sheetRow = sheet.getRow(i);
            Cell cell = sheetRow.getCell(0);
            Double hotelId = cell.getNumericCellValue();
            cell = sheetRow.getCell(1);
            Double mtHotelId = cell.getNumericCellValue();
            log.info("========hotelId的值为{}mtHotelId的值为{}=======",hotelId.intValue(),mtHotelId.intValue());
            Integer price=5000;
            if(redisService.exists(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_PRICE)){
                price= (Integer) redisService.get(CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_PRICE);
            }
            SwitchJoinActiveHotelEntity switchJoinActiveHotelEntity=new SwitchJoinActiveHotelEntity();
            switchJoinActiveHotelEntity.setCreateTime(new Date());
            switchJoinActiveHotelEntity.setHotelId(hotelId.intValue());
            switchJoinActiveHotelEntity.setModifyTime(new Date());
            switchJoinActiveHotelEntity.setMtHotelId(mtHotelId.intValue());
            switchJoinActiveHotelEntity.setPrice(price);
            switchJoinActiveHotelEntity.setRemark("");
            switchJoinActiveHotelEntities.add(switchJoinActiveHotelEntity);
        }
        if(switchJoinActiveHotelEntities.size()>0){
            int flag= switchJoinActiveHotelMapper.insertList(switchJoinActiveHotelEntities);
            if(flag>0){
                String key=CommonConstants.SWITCH_JOIN_ACTIVE_HOTEL_LIST_FOR_ORDER;
                switchJoinActiveHotelEntities.forEach(e->{
                    redisService.hmSet(key,e.getMtHotelId(),e.getPrice());
                });
            }
        }
    }
    /**
     * 夜间控制数据列表
     */
    @Override
    public Result<Object> limitNightList() {
        Map<String,String> map=new HashMap<>();
        //涨价可推送，降价不推送
        String addPrice="swmt_check_gt_price_hour_not";
        if(redisService.exists(addPrice)){
            map.put("addPrice", String.valueOf(redisService.get(addPrice)));
        }else{
            map.put("addPrice", "");
        }
        //满房可推送,开房不推送
        String closeRoom="swmt_before_not_now_can_no_push_in_hour";
        if(redisService.exists(closeRoom)){
            map.put("closeRoom", String.valueOf(redisService.get(closeRoom)));
        }else{
            map.put("closeRoom", "");
        }
        //载入新一天，限制时间段不载入，过后可载入。
        String loading="mtsw_job_status_price_not_load_new_day_hour_time_open_condition";
        if(redisService.exists(loading)){
            map.put("loading", String.valueOf(redisService.get(loading)));
        }else{
            map.put("loading", "");
        }
        //推送价格最低为标准价
        String lowerPrice="swmt_library_not_check_min_hour";
        if(redisService.exists(lowerPrice)){
            map.put("lowerPrice", String.valueOf(redisService.get(lowerPrice)));
        }else{
            map.put("lowerPrice", "");
        }
        return new Result<>(map);
    }

    /**
     * 夜间控制
     * @param map
     * @return
     */
    @Override
    public Result<Object> setLimitNight(Map<String, String> map) {
        String addPrice=map.get("addPrice");
        if(StringUtil.isBlank(addPrice)){
            redisService.remove("swmt_check_gt_price_hour_not");
        }else{
            redisService.set("swmt_check_gt_price_hour_not",addPrice);
        }
        //满房可推送,开房不推送
        String closeRoom=map.get("closeRoom");
        if(StringUtil.isBlank(closeRoom)){
            redisService.remove("swmt_before_not_now_can_no_push_in_hour");
        }else{
            redisService.set("swmt_before_not_now_can_no_push_in_hour",closeRoom);
        }
        //载入新一天，限制时间段不载入，过后可载入。
        String loading=map.get("loading");
        if(StringUtil.isBlank(loading)){
            redisService.remove("mtsw_job_status_price_not_load_new_day_hour_time_open_condition");
        }else{
            redisService.set("mtsw_job_status_price_not_load_new_day_hour_time_open_condition",loading);
        }
        //推送价格最低为标准价
        String lowerPrice=map.get("lowerPrice");
        if(StringUtil.isBlank(lowerPrice)){
            redisService.remove("swmt_library_not_check_min_hour");
        }else{
            redisService.set("swmt_library_not_check_min_hour",lowerPrice);
        }
        return new Result<>();
    }
    /**
     * 普通酒店 日期下降
     */
    @Override
    public Result<Object> adjsutCommonHotelSaleDays() {
        List<Integer> hotelIds=switchHotelUpMapper.selectCommonHotelList();
        if(ObjectUtils.isEmpty(hotelIds)){
            return new Result<>();
        }
        for(Integer hotelId:hotelIds){
            // int vipDay=getDaysCommonBaseSetForVip();//5
            int vipDay=5;
            // int normalDay=getDaysCommonBaseSetForNormal();//3
            int normalDay=1;
            if(ObjectUtils.isEmpty(hotelId)){
                return new Result<>();
            }
            List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectByHotelId(hotelId);
            BatchPushRoomVo batchPushRoomVo=new BatchPushRoomVo();
            batchPushRoomVo.setHotelId(hotelId);
            List<RoomDataEntityVo> roomDataEntitys=new ArrayList<>();
            for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
                RoomStatusModelVo roomStatusModelVo;
                String endTimes=DateUtil.getDate(vipDay);
                String statrTimes=DateUtil.getDate(normalDay);
                RoomDataEntityVo roomDataEntityVo1=new RoomDataEntityVo();
                roomDataEntityVo1.setRoomId(switchCreateRoomEntity.getRoomId());
                roomDataEntityVo1.setEndDate(endTimes);
                roomDataEntityVo1.setStartDate(statrTimes);
                roomStatusModelVo=new RoomStatusModelVo();
                roomStatusModelVo.setChannel(StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName()));
                roomStatusModelVo.setSaleStatus(0);
                roomDataEntityVo1.setRoomStatusModel(roomStatusModelVo);
                roomDataEntitys.add(roomDataEntityVo1);
            }
            batchPushRoomVo.setRoomDataEntitys(roomDataEntitys);
            log.info("=======batchPushRoomVo的值为{}==========",JacksonUtil.objectToJson(roomDataEntitys));
            Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            if (result.getMsg().toString().contains("请求过于频繁")) {
                try {
                    Thread.sleep(6000);
                    switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        return new Result<>();
    }
}
